#include <bits/stdc++.h>
#define int long long
using namespace std;
int c,t,n,k,a[114514],b[114514],got=1,gt[114514],an;
vector<int> e[114514],f[114514];
bool vis[114514];
void ss(){
	int an=1;
	cout<<an<<"\n";
}
void dfs(int x,int c){
	vis[x]=1;
	if(c==n-2){
		an++; 
		vis[x]=0;
		return;
	}
	for(int i=0;i<e[x].size();i++){
		if(vis[e[x][i]]) continue;
		dfs(e[x][i],c+1);
	}
	vis[x]=0;
	return;
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>c>>t;
	for(int it=1;it<=t;it++){
		cin>>n>>k;
		for(int i=1,j,k;i<n;i++){
			cin>>j>>k;
			a[i]=j; b[i]=k;
			f[j].push_back(i);
			f[k].push_back(i);
		}
		for(int i=1;i<n;i++){
			for(int j=0;j<f[a[i]].size();j++){
				if(f[a[i]][j]!=i) e[i].push_back(f[a[i]][j]);
			}
			for(int j=0;j<f[b[i]].size();j++){
				if(f[b[i]][j]!=i) e[i].push_back(f[b[i]][j]);
			}
		}
		for(int i=1;i<=k;i++) cin>>gt[i];
		if(c==18){
			cout<<"1\n";
			continue;
		}
		if(c<18){
			memset(vis,0,sizeof vis);
			an=0;
			dfs(gt[1],1);
			cout<<an<<"\n";
			continue;
		}
	}
}
