#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=1e5+10,M=N*2,inf=0x3f3f3f3f;
int n,k,ans;
struct E1{int from,to,nxt;}e1[M];
int cnt1,hd1[N];
void adde1(int u,int v){e1[++cnt1].to=v,e1[cnt1].from=u,e1[cnt1].nxt=hd1[u],hd1[u]=cnt1;}
struct E2{int from,to,nxt;}e2[M];
int cnt2,hd2[N];
void adde2(int u,int v){e2[++cnt2].to=v,e2[cnt2].from=u,e2[cnt2].nxt=hd2[u],hd2[u]=cnt2;}
struct Edge{int a,b;}e[M];
map<pair<int,int>,int> mp,mp2;
int st[N];
void dfs1(int x,int fa){
	if(fa!=-1) for(int i=hd1[x];i;i=e1[i].nxt){
		int y=e1[i].to;
		if(y==fa) continue;
		adde2(mp[{fa,x}],mp[{x,y}]),adde2(mp[{x,y}],mp[{fa,x}]);
	}
	for(int i=hd1[x];i;i=e1[i].nxt){
		for(int j=hd1[x];j;j=e1[j].nxt){
			int y=e1[i].to,z=e1[j].to;
			if(y==fa||z==fa||y==z) continue;
			adde2(mp[{x,y}],mp[{x,z}]),adde2(mp[{x,z}],mp[{x,y}]);
		}
	}
	for(int i=hd1[x];i;i=e1[i].nxt){
		int y=e1[i].to;
		if(y==fa) continue;
		dfs1(y,x);
	}
}
map<string,int> P;
int Tong[N];
int tot=0;
void dfs2(int x,int fa){
	if(tot==n-2){
		string Tree;
		for(int i=1;i<=cnt2/2;i++) Tree=Tree+(char)(Tong[i]+'0');
		if(!P[Tree]) P[Tree]=1,ans++;
		return;
	}
	for(int i=hd2[x];i;i=e2[i].nxt){
		int y=e2[i].to;
		if(y==fa) continue;
		++tot,Tong[mp2[{x,y}]]=1;
		dfs2(y,x);
		--tot,Tong[mp2[{x,y}]]=0;
	}
}
void solve(){
	scanf("%d%d",&n,&k);
	ans=cnt1=cnt2=0,memset(e1,0,sizeof e1),memset(e2,0,sizeof e2),memset(e,0,sizeof e);
	for(int i=1;i<n;i++){
		scanf("%d%d",&e[i].a,&e[i].b);
		adde1(e[i].a,e[i].b),adde1(e[i].b,e[i].a);
		mp[{e[i].a,e[i].b}]=mp[{e[i].b,e[i].a}]=i;
	}
	dfs1(1,-1);
	for(int i=1;i<=cnt2;i++){
		mp2[{e2[i].from,e2[i].to}]=1;
//		printf("(e%d,e%d)\n",e2[i].from,e2[i].to);
	}
	for(int i=1;i<=k;i++){
		scanf("%d",&st[i]);
		dfs2(st[i],-1);
	}
	printf("%d\n",ans);
}

int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int c,T;
	scanf("%d%d",&c,&T);
	while(T--) solve();
	return 0;
}


