#include<bits/stdc++.h>
using namespace std;
int vis[15],v[15][15],ans,bl,c,t,n,k,a[15],b[15];
vector<int> r[15];
void sr(int z,int k,int y){
	if(bl+1==n){
		ans++;
		return;
	}
	vis[y]=1;
	if(r[y].size()==1&&z){
		for(int i=0;i<r[k].size();i++){
			if(vis[r[k][i]]) continue;
			bl++;
			sr(z,k,r[k][i]);
			bl--;
		}
		for(int i=0;i<r[z].size();i++){
			if(vis[r[z][i]]) continue;
			bl++;
			sr(k,z,r[z][i]);
			bl--;
		}
	if(z) vis[y]=0;
		return;
	}
	for(int i=0;i<r[k].size();i++){
		if(vis[r[k][i]]) continue;
		bl++;
		sr(y,k,r[k][i]);
		bl--;
	}
	for(int i=0;i<r[y].size();i++){
		if(vis[r[y][i]]) continue;
		bl++;
		sr(k,y,r[y][i]);
		bl--;
	}
	if(z) vis[y]=0;
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%d%d",&c,&t);
	for(int i=1;i<=t;i++){
		scanf("%d%d",&n,&k);
		for(int j=1;j<n;j++){
			scanf("%d%d",&a[j],&b[j]);
			r[a[j]].push_back(b[j]);
			r[b[j]].push_back(a[j]);
		}
		bl=1;
		vis[1]=vis[3]=1;
		sr(0,1,3);
		cout<<ans;
		
	}
	return 0;
}

