#include<cstdio>
#include<cctype>
#include<queue>
#include<cmath>
#include<bitset>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ren for(int i=first[x];i;i=next[i])
using namespace std;
inline int read() {
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c==‘-‘) f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-‘0‘;
return x*f;
}
typedef long long ll;
const int maxn=310;
const int mod=998244353;
int f[maxn][maxn],A[maxn][maxn];
int check(int x1,int x2,int y1,int y2) {
return A[x2][y2]-A[x1-1][y2]-A[x2][y1-1]+A[x1-1][y1-1];
}
int dp(int l,int r) {
int& ans=f[l][r];
if(ans>=0) return ans;
if(l>=r) return ans=1;ans=0;
if(!check(l+1,r,l,l)) ans=dp(l+1,r);
rep(i,l,r-1) if(!check(l+1,i,l,l)&&!check(l,l,i+1,r)&&!check(l+1,i,i+1,r)) {
(ans+=((ll)dp(l+1,i)*dp(i+1,r))%mod)%=mod;
}
return ans;
}
int main() {
dwn(T,read(),1) {
memset(f,-1,sizeof(f));
memset(A,0,sizeof(A));
int n=read(),m=read();
while(m--) {
int a=read(),b=read();
A[b][a]=1;if(a==b) f[1][n]=0;
}
rep(i,1,n) rep(j,1,n) A[i][j]+=A[i][j-1]+A[i-1][j]-A[i-1][j-1];
printf("%d\n",dp(1,n));
}
return 0;
}