#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
struct EDGE{
	int v,nxt;
}e[N<<1];
int n,k,h[N],u[N],v[N],cnt,ans;
bool vis[N];
void add_edge(int u,int v){
	e[cnt]={v,h[u]};
	h[u]=cnt++;
}
void getans(int u,int tmp){
	if(tmp==n-1){
		ans++;
		return;
	}
	for(int i=h[u];~i;i=e[i].nxt){
		int v=e[i].v;
		if(!vis[v]){
			vis[v]=1;
			getans(v,tmp+1);
			vis[v]=0;
		}
	}
}
void solve(){
	memset(h,-1,sizeof(h)),cnt=0;
	memset(vis,0,sizeof(vis)),ans=0;
	cin>>n>>k;
	for(int i=1;i<n;i++){
		cin>>u[i]>>v[i];
		for(int j=1;j<i;j++)
			if(u[i]==u[j]||u[i]==v[j]||v[i]==u[j]||v[i]==v[j]) add_edge(i,j),add_edge(j,i);
	}
	for(int i=1,q;i<=k;i++){
		cin>>q;
		vis[q]=1;
		getans(q,1);
		vis[q]=0;
	}
	cout<<ans<<"\n";
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int c,T;
	cin>>c>>T;
	while(T--) solve();
	return 0;
}
