#include<bits/stdc++.h>
using namespace std;
struct line{
	int a,b;
};
int n,k;
int v[100005]={0};
bool vis[100005];
int maps[100005][100005];
int tmp[100005][100005]={0};
int find(int f,int num){
	if(num=n-1){
		return 1;
	}
	vis[f]=true;
	int ans=0;
	for(int i=0;i<n-1;i++){
		if(!vis[f]&&maps[f][i]==1&&i!=f){
			ans+=find(i,num+1);
		}
	}
	vis[f]=false;
	return ans;
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int c,T;
	scanf("%d%d",&c,&T);
	while(T--){
		memset(v,0,sizeof(v));
		line arr[100005];
		memset(maps,0,sizeof(maps));
		memset(tmp,0,sizeof(tmp));
		scanf("%d%d",&n,&k);
		
		for(int i=0;i<n-1;i++){
			cin>>arr[i].a>>arr[i].b;
			tmp[arr[i].a][v[arr[i].a]++]=i;
			tmp[arr[i].b][v[arr[i].b]++]=i;
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<v[i];j++){
				for(int k=j;k<v[i];k++){
					maps[tmp[i][j]][tmp[i][k]]=1;
				}
			}
		}
		int fx[100005]={0};
		for(int i=0;i<k;i++){
			cin>>fx[i];
		}
		int ans=0;
		for(int i=0;i<k;i++){
			ans+=find(i,1);
		}
		cout<<ans;
	}
	return 0;
}
