#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
#define N 115
#define mo 10007
using namespace std;
typedef long long LL;
int n,m,t,a[N],a1[12][2];
LL ans,js[N],ny[N],f[N][N];
bool bz[N],bf[N],bc[N];
LL ksm(LL k,LL n)
{
LL s=1;
for(;n;n>>=1,k=k*k%mo) if(n&1) s=s*k%mo;
return s;
}
LL C(int n,int m)
{
if(n<m) return 0;
return js[n]*ny[m]%mo*ny[n-m]%mo;
}
void dfs(int k,bool p1,bool p2,LL v,int c)
{
if(k>m)
{
LL s1=js[c],s2=0,s3=0,s4=0;
if(!p1)
{
int cnt=0;LL vp=1;
fo(i,0,n-1) if(!bf[i]&&!bc[i]) cnt++;
fo(i,0,cnt)
{
s2=(s2+vp*js[c-i]*C(cnt,i)%mo+mo)%mo;
vp=-vp;
}
}
if(!p2)
{
int cnt=0;LL vp=1;
fo(i,0,n-1) if(!bf[i]&&!bc[n-1-i]) cnt++;
fo(i,0,cnt)
{
s3=(s3+vp*js[c-i]*C(cnt,i)%mo+mo)%mo;
vp=-vp;
}
}
if(!p1&&!p2)
{
memset(f,0,sizeof(f));
f[0][0]=1;
fo(i,0,(n+1)/2-1)
{
fo(j,0,2*(i+1))
{
f[i+1][j]=f[i][j];
if(n-1-i!=i)
{
if(j>0)
{
LL c1=(!bf[i]&&!bc[i])+(!bf[i]&&!bc[n-1-i])+(!bf[n-1-i]&&!bc[i])+(!bf[n-1-i]&&!bc[n-1-i]);
f[i+1][j]=(f[i+1][j]+f[i][j-1]*c1)%mo;
}
if(j>1)
{
LL c1=2*(!bf[i]&&!bc[i]&&!bf[n-1-i]&&!bc[n-1-i]);
f[i+1][j]=(f[i+1][j]+f[i][j-2]*c1)%mo;
}
}
else if(!bf[i]&&!bc[i]&&j>0) f[i+1][j]=(f[i+1][j]+f[i][j-1])%mo;
}
}
LL vp=1;
fo(i,0,n) s4=(s4+vp*js[c-i]*f[(n+1)/2][i]%mo+mo)%mo,vp=-vp;
}
ans=(ans+v*(s1-s2-s3+s4)%mo+mo)%mo;
return;
}
dfs(k+1,p1,p2,v,c);
int x=a1[k][0],y=a1[k][1];
if(!bf[x]&&!bc[y])
{
bf[x]=1,bc[y]=1;
dfs(k+1,p1||(x==y),p2||(x==n-1-y),-v,c-1);
bf[x]=0,bc[y]=0;
}
}
int main()
{
cin>>t;
js[0]=1;
fo(i,1,100) js[i]=js[i-1]*(LL)i%mo;
ny[100]=ksm(js[100],mo-2);
fod(i,99,0) ny[i]=ny[i+1]*(LL)(i+1)%mo;
while(t--)
{
scanf("%d%d",&n,&m);
memset(bf,0,sizeof(bf));
memset(bc,0,sizeof(bc));
ans=0;
fo(i,1,m) scanf("%d%d",&a1[i][0],&a1[i][1]);
dfs(1,0,0,1,n);
printf("%lld\n",ans);
}
}