#include<bits/stdc++.h>
#define int long long 
#define rep(i,a,b)	for(int i = (a);i<=(b);i++)
#define lep(i,a,b)	for(int i = (a);i>=(b);i--)
using namespace std;
const int N = 1e5+10;
const int M = 1e9+7;
int c,t,n,k,x,u,v,cnt,ans;
struct edge{
	int u,v;
}e[N];
int f[N];
bool vis[N];
vector<int> g[N];
inline void dfs(int u,int fa,int c){
	if(!c){
		f[u]++;
		return;
	}
	for(int i = 0;i<(int)g[u].size();i++){
		int v = g[u][i];
		if(v == fa)	continue;
		if(f[v]){
			f[u]+=f[v];
			continue;
		}
		if(!vis[v]){
			vis[v] = 1;
			dfs(v,u,c-1);
			if(!f[u])	f[u] = f[v];
			else f[u]*=f[v];
			vis[v] = 0;
		}
	}
} 
inline void solve(){
	cin>>n>>k;
	cnt = 0;
	rep(i,1,n-1){
		cin>>u>>v;
		if(u>v)swap(u,v);
		e[++cnt] = edge{u,v};
	}
	rep(i,1,k)	cin>>x;
	if(n<=5 && k == 1){
		rep(i,1,cnt)	g[i].clear();
		rep(i,1,cnt){
			rep(j,i+1,cnt){
				if(i == j)	continue;
				if(e[i].u == e[j].u || e[i].v == e[j].u || e[i].u == e[j].v || e[i].v == e[j].v){
					g[i].push_back(j);
					g[j].push_back(i);
				}
			}
		}
		rep(i,1,cnt)	f[i] = 0;
		f[x] = 1;
		vis[x] = 1;
		dfs(x,0,cnt-1);
		ans = f[x];
	}
	else{
		ans = 1;
	}
	cout<<ans<<"\n";
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cin>>c>>t;
	while(t--)	solve();
	return 0;
}
