参照基尔霍夫矩阵的定义建图
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <fstream>
#include <cmath>
#include <functional>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <numeric>
#include <bitset>
#include <iomanip>
using namespace std;
typedef long long ll;
#define lson l , m ,rt<<1
#define rson m+1,r,rt<<1|1
typedef vector<string> VS;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef pair<int, int> pii;
const int maxn = 14;
ll det[maxn][maxn];
int n,m;
bool g[maxn][maxn];
ll Det(int n)
{
int i,j,k;
ll ans=1;
for(i=0;i<n;++i)
{
for(j=i+1;j<n;++j)
{
while(det[j][i])
{
ll t=det[i][i]/det[j][i];
for(k=i;k<n;++k)
{
det[i][k]-=det[j][k]*t;
}
for(k=i;k<n;++k)
swap(det[i][k],det[j][k]);
ans*=-1;
}
}
}
for(i=0;i<n;++i) ans*=det[i][i];
return ans;
}
int main() {
int i,u,v,T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
memset(det,0,sizeof(det));
for(i=0;i<m;++i)
{
scanf("%d%d",&u,&v);
--u,--v;
det[u][u]++;
det[v][v]++;
det[v][u]=-1;
det[u][v]=-1;
}
ll ans=Det(n-1);
printf("%lld\n",ans);
}
return 0;
}