#include<bits/stdc++.h>
#define int long long
using namespace std;
const int inf=1e9+7;
int in(){
	int ans=0,f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) ans=ans*10+c-'0';
	return ans*f;
}
int T,c;
int n,k;
int e[100010];
int fir[100010],ne[200010],en[200010],cnt;
int t1[100010],t2[100010];
int f1[100010],f2[100010];
void add(int u,int v){
	cnt++;
	ne[cnt]=fir[u];
	en[cnt]=v;
	fir[u]=cnt;
}
int jc(int x){
	int sum=1;
	for(int i=2;i<=x;i++) sum=(sum*i)%inf;
	return sum;
}
int v[100010],ans;
int dfs(int p){
//	printf("%lld\n",p);
	for(int i=fir[en[2*p]];i;i=ne[i]){
		int q=(i+1)/2;
		if(!v[q]&&q!=p){
			v[q]=p;
		}
	}
	for(int i=fir[en[2*p-1]];i;i=ne[i]){
		int q=(i+1)/2;
		if(!v[q]&&q!=p){
			v[q]=p;
		}
	}
	int sum2=1,cnt2=0;
	int sum1=1,cnt1=0;
	for(int i=fir[en[2*p]];i;i=ne[i]){
		int q=(i+1)/2;
		if(v[q]==p&&q!=p){
			cnt1++;
			sum1=(sum1*dfs(q))%inf;
		}
	}
	for(int i=fir[en[2*p-1]];i;i=ne[i]){
		int q=(i+1)/2;
		if(v[q]==p&&q!=p){
			cnt2++;
			sum2=(sum2*dfs(q))%inf;
		}
	}
	return (sum1%inf*jc(cnt1)%inf*sum2%inf*jc(cnt2)%inf);
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	c=in();T=in();
	while(T--){
		n=in();k=in();
		int u,w;
		memset(fir,0,sizeof(fir));
		memset(en,0,sizeof(en));
		cnt=0;
		for(int i=2;i<=n;i++){
			u=in(),w=in();
			add(u,w);
			add(w,u);
		}
		for(int i=1;i<=k;i++) e[i]=in();
		ans=0;
		for(int i=1;i<=k;i++){
			memset(v,0,sizeof(v));
			v[e[i]]=-1;
			int an1=dfs(e[i]);
			ans+=an1%inf;
		}
		printf("%lld\n",ans);
	}
	return 0;
}
