#include <bits/stdc++.h>
using namespace std;
#define int long long
struct Node{
	int v,id;
};
vector<Node> e[500006];
int tot,n,f[500006],b[500006],ans,k,u,v,p,T;
struct node{
	int u,v;
}a[500006];
void dfs(int u,int fa,int id){
	for(Node p:e[u]){
		int v = p.v,idx = p.id;
		if(v == fa) continue;
		dfs(v,u,idx);
	}
	for(int i = 0;i < e[u].size(); i++)
		for(int j = i+1;j < e[u].size(); j++)
			a[++tot] = {e[u][i].id,e[u][j].id};
}
int find(int x){
	if(f[x] == x) return x;
	return f[x] = find(f[x]);
}
void dfsx(int x){
	if(x == tot+1){
		for(int i = 1;i <= n-1; i++)
			f[i] = i;
		for(int i = 1;i <= tot; i++)
			if(b[i]){
				int fx = find(a[i].u),fy = find(a[i].v);
				if(fx != fy) f[fx] = fy;
			}
		int r = find(1);
		for(int i = 2;i <= n-1; i++)
			if(find(i) != r)
				return ;
		ans++;
		return ;
	}
	b[x] = 1;
	dfsx(x+1);
	b[x] = 0;
	if(p != x) dfsx(x+1);
}
void solve(){
	memset(a,0,sizeof(a));
	ans = 0;tot = 0;
	for(int i = 1;i <= n; i++)
		e[i].clear();
	cin >> n >> k;
	for(int i = 1;i <= n-1; i++){
		cin >> u >> v;
		e[u].push_back({v,i});
		e[v].push_back({u,i});
	}
	dfs(1,0,0);
	for(int i = 1;i <= k; i++){
		cin >> p;
		dfsx(1);
	}
	cout << ans << endl;
}
main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cin >> T >> T;
	while(T--)
		solve();
	return 0;
}
