#include <iostream>
#include <vector>
#define mod 1000000007
#define int long long
using namespace std;
int n,k,c,t,ans; 
struct node{
	int u,v;
};
vector<node>e;
int s[1111][1111];
void dfs(int u,int v){
	int i,j;
	bool flag=0;
	for(i=1;i<=n;i++){
		if(i==v||s[u][i]==0) continue;
		flag=1;
		s[i][u]=s[u][i]=0;
		dfs(i,u);
		s[i][u]=s[u][i]=1;
	}
	for(i=1;i<=n;i++){
		if(i==u||s[v][i]==0) continue;
		flag=1;
		s[i][v]=s[v][i]=0;
		dfs(i,v);
		s[i][v]=s[v][i]=1;
	}
	if(flag==0) ans++;
}
signed main(){
	int u,v,i,j,s;
	cin>>c>>t;
	while(t--){
		cin>>n>>k;
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++) s[i][j]=0;
		}
		e.clear();
		e.push_back({0,0});	
		for(i=1;i<n;i++){
			cin>>u>>v;
			s[u][v]=s[v][u]=1;
			e.push_back({u,v});
		}
		cin>>s;
		s[e[s].u]][e[s].v]=s[e[s].v][e[s].u]=0;
		dfs(e[s].u,e[s].v);
	}
}

