#include<bits/stdc++.h>
using namespace std;
vector<int>G[100005];
bool ck[100005];
int n,m,ans=0;
void dfs(int a,int t){
	if(t==n-1){
		ans++;
		return;
	}
	int sz=G[a].size();
	for(int i=0;i<sz;i++){
		if(!ck[G[a][i]]){
			ck[G[a][i]]=1;
			dfs(G[a][i],t+1);
			ck[G[a][i]]=0;
		}
	}
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int c,T;
	cin>>c>>T;
	while(T--){
		map<pair<int,int>,int>mp;
		vector<pair<int,int>>H;
		memset(G,0,sizeof(G));
		memset(ck,0,sizeof(ck));
		ans=0;
		cin>>n>>m;
		for(int i=1;i<n;i++){
			int u,v;
			cin>>u>>v;
			H.push_back({u,v});
			mp[{u,v}]=i;
		}
		int sz=H.size();
		for(int i=0;i<sz;i++)
			for(int j=i+1;j<sz;j++)
				if(H[i].first==H[j].first||H[i].first==H[j].second||H[i].second==H[j].first||H[i].second==H[i].second){
					G[mp[H[i]]].push_back(mp[H[j]]);
					G[mp[H[j]]].push_back(mp[H[i]]);
				}
		for(int i=0;i<m;i++){
			int v;
			cin>>v;
			ck[v]=1;
			dfs(v,1);
			ck[v]=0;
		}		
		cout<<ans<<endl;	
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
