#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,m,c,T,k,q,sta[1000],top=0,ans;
vector<int> e[N];
struct{
	int u,v,nxt;
}edge[N];
int head[N],cnt=0,size[N];
void add(int u,int v){
	size[u]++;
	cnt++;
	edge[cnt].u=u;
	edge[cnt].v=v;
	edge[cnt].nxt=head[u];
	head[u]=cnt;
}
bool vis[N];
bool check(){
	for(int i=1;i<n;i++){
		if(!vis[i]) return 0;
	}
	return 1;
}
void dfs(int u){
	if(check()){
		ans++;
		return;
	}
	for(auto i:e[u]){
		if(vis[i]) continue;
		vis[i]=1;
		dfs(i);
		vis[i]=0;
	}
	return;
}

int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	bool flag=1;
	cin>>c>>T;
	while(T--){
		ans=0;
		cin>>n>>k;
		for(int i=1;i<n;i++){
			int u,v;
			cin>>u>>v;
			add(u,v);
			add(v,u);
//			e[u].push_back(v);
//			e[v].push_back(u);
		}
		cin>>q;
		for(int i=1;i<=n;i++){
			//cerr<<size[i]<<" ";
			if(size[i]>1){
				for(int j=head[i];j!=0;j=edge[j].nxt){
					sta[++top]=j;
					//cout<<edge[j].v<<" ";
				}
				for(int j=1;j<=top;j++){
					//cout<<j<<" ";
					for(int k=j+1;k<=top;k++){
						//cerr<<sta[j]/2<<" ";
						e[sta[j]/2].push_back(sta[k]/2);
						e[sta[k]/2].push_back(sta[j]/2);
					}
				}
			}
		}
		vis[q]=1;
		dfs(q);
		cout<<ans<<"\n";
	}
	return 0;
}


