#include<bits/stdc++.h>
using namespace std;
int in(){
	int s=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		s=s*10+c-'0';
		c=getchar();
	}
	return s*f;
}
int t,c,n,k;
int Fir[100010],fr[100010],To[200010],Nxt[200010],Cnt;
void Add(int x,int y){
	Cnt++;
	To[Cnt]=y;
	fr[Cnt]=x;
	Nxt[Cnt]=Fir[x];
	Fir[x]=Cnt;
}
int fir[100010],sum[100010],to[200010],nxt[200010],cnt;
void add(int x,int y){
	cnt++;
	to[cnt]=y;
	nxt[cnt]=fir[x];
	fir[x]=cnt;
	sum[x]++;
}
void dfs1(int x,int fa,int lst){
	for(int i=Fir[x];i;i=Nxt[i]){
		int y=To[i];
		if(y!=fa){
			add(lst,i);
			add(i,lst);
			dfs1(y,x,i);
		}
	}
}
bool book[100010];
int f[100010];
long long ans;
void dfs(int x,int summ){
	if(summ==n-2){
		ans++;
//		for(int i=1;i<=n-2;i++)
//			printf("%d %d %d\n",fr[f[i]],To[f[i]],f[i]);
//		puts("");
		return;
	}
	for(int i=fir[x];i;i=nxt[i]){
		int y=to[i];
		if(!book[i]&&!book[i+i%2]){
			book[i]=book[i+i%2]=1;
			f[summ+1]=i;
			dfs(y,summ+1);
			book[i]=book[i+i%2]=0;
		}
	}
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	c=in();t=in();
	while(t--){
		n=in();k=in();
		for(int i=1;i<n;i++){
			int u=in(),v=in();
			Add(u,v);
			Add(v,u);
		}
		dfs1(1,0,0);
		for(int i=1;i<=k;i++){
			int e=in();
			f[1]=e;
			book[e]=book[e+e%2]=1;
			dfs(e,1);
		}
		printf("%lld\n",ans);
	}
	
	
	
	
	
	
	
	
	
	return 0;
}
