#include<bits/stdc++.h>
using namespace std;
#define pb push_back  
const int N=2e5+2;
vector<int>g[N],h[N];
int v[N],ans,cnt;
int n,k;
set<pair<int,int>>s;
map<set<pair<int,int> > ,bool>mp;
void dfs(int x,int st){
	v[x]=1;
	if(mp[s]==0)++ans,mp[s]=1;
	for(int i=st;i<h[x].size();++i){
		if(v[h[x][i]])continue;
		for(int j=0;j<h[h[x][i]].size();++j){
			s.insert({i,h[x][i]});
			s.insert({h[x][i],i});
			dfs(h[x][i],j);
			s.erase({i,h[x][i]});
			s.erase({h[x][i],i});
		}
	}
	for(int i=0;i<st;++i){
		if(v[h[x][i]])continue;
		for(int j=0;j<h[h[x][i]].size();++j){
			s.insert({i,h[x][i]});
			s.insert({h[x][i],i});
			dfs(h[x][i],j);
			s.erase({i,h[x][i]});
			s.erase({h[x][i],i});
		}
	}
	v[x]=0;
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout); 
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int taskid,T;cin>>taskid>>T;
	while(T--){
		mp.clear();
		cin>>n>>k;
		for(int i=1;i<=n;++i)g[i].clear(),h[i].clear();
		for(int i=1;i<n;++i){int u,v;cin>>u>>v;g[u].pb(i),g[v].pb(i);}
		for(int i=1;i<=n;++i){
			for(int j=0;j<g[i].size();++j){
				for(int l=j+1;l<g[i].size();++l){
					h[g[i][j]].pb(g[i][l]);
					h[g[i][l]].pb(g[i][j]);
				}
			}
		}
		int p;
		for(int i=1;i<=k;++i)cin>>p;
		if(n<=5){
			ans=0;
			dfs(p,0);
			cout<<ans<<'\n';
		}
		else {
			cout<<"1\n";
		}
	}
	return 0;
}
