#include <iostream>
#include <cstdio>
#include <vector>
#define pb push_back
using namespace std;
const int N=105;
int Takanashi_Hoshino, AFO, n, k, ans, u, v, rt, l[N], r[N], cnt;
bool vis[N], flag;
vector<int> e[N];

void dfs(int u, int v){
//	printf("dfs (%d, %d), cnt = %d\n", u, v, cnt);
	for(int x: e[u]){
		if(!vis[x]){
			vis[x] = true;
			cnt++; flag = false;
			dfs(u, x);
			if(flag) cnt--;
			vis[x] = false;
		}
	}
	for(int x: e[v]){
		if(!vis[x]){
			vis[x] = true;
			cnt++; flag = false;
			dfs(v, x);
			if(flag) cnt--;
			vis[x] = false;
		}
	}
	if(cnt==n-1){
		ans++;
		flag = true;
	}
	return;
}

int main(){
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	cin>>AFO>>Takanashi_Hoshino;
	while(Takanashi_Hoshino--){
		ans = 0;
		cin>>n>>k;
		for(int i=1; i<n; i++){
			cin>>u>>v;
			e[u].pb(v); e[v].pb(u);
			l[i]=u, r[i]=v;
		}
		while(k--){
			cnt = 1;
			cin>>rt; vis[l[rt]] = vis[r[rt]] = true;
			dfs(l[rt], r[rt]);
			vis[l[rt]] = vis[r[rt]] = false;
		}
		cout<<ans<<'\n';
		for(int i=1; i<=n; i++) e[i].clear();
		for(int i=1; i<=n; i++) vis[i] = false;
		flag = false;
	}
	return 0;
}
