#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i <= b; i++)
const int N = 1e5 + 5;
inline int read() {
	int ans = 0, f = 1; char ch = getchar();
	for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -f;
	for(; ch >= '0' && ch <= '9'; ch = getchar()) ans = (ans << 3) + (ans << 1) + ch - '0';
	return f * ans;
}
int u[N], v[N], n, k, ans;
vector<int> a[N];
bool vis[N];
void dfs(int ne, int dep) {
	if(dep = n - 1) {
		ans++;
		return ;
	}
	rep(i,0,a[ne].size() - 1) {
		int nx = a[ne][i];
		if(!vis[nx]) {
			vis[nx] = 1;
			dfs(nx, dep + 1);
			vis[nx] = 0;
		}
	}
}
int main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	int c = read(), T = read();
	while(T--) {
		ans = 0;
		 n = read(), k = read();
		rep(i,1,n - 1) {
			u[i] = read();  v[i] = read();
		}
		rep(i,1,n - 1) {
			rep(j,1,n - 1) {
				if(i == j ) continue;
				if(u[j] == u[i] || u[j] == v[i] || v[j] == u[i] || v[j] == u[j]) 
					a[i].push_back(j);
			}
		}
		if(c <= 6) {
			memset(vis, 0, sizeof(vis));
			int e = read();
			vis[e] = 1;
			dfs(e, 1);
			cout << ans << endl;
		} 
	}
	
	return 0;
} 
