#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
int fac[1000010],tid,T,n,K,sx[1000010],sy[1000010],h[1000010],cnt,p[1000010];
long long ans;
struct node{int s,t;}a[1000010];
void add(int x,int y){a[++cnt].s=h[x],a[cnt].t=y,h[x]=cnt;}
int rd(){
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x;
}
void dfs(int x,int fa){
	int tmp=0;
	for(int i=h[x];i;i=a[i].s)
		if(a[i].t!=fa)
			dfs(a[i].t,x),tmp++;
	ans=ans*fac[tmp]%MOD;
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	tid=rd(),T=rd();
	while(T--){
		n=rd(),K=rd();
		fac[0]=1;
		for(int i=1;i<=n;i++)h[i]=0,fac[i]=fac[i-1]*1ll*i%MOD;
		cnt=0;
		for(int i=1;i<=n-1;i++){
			sx[i]=rd(),sy[i]=rd();
			add(sx[i],sy[i]),add(sy[i],sx[i]);
		}
		for(int i=1;i<=K;i++)p[i]=rd();
		if(K==1){
			ans=1;
			dfs(sx[p[1]],sy[p[1]]);
			dfs(sy[p[1]],sx[p[1]]);
			printf("%lld\n",ans);
			continue;
		}
		if(tid==18){
			printf("1\n");
			continue;
		}
		if(tid>=19&&tid<=21){
			ans=0;
			for(int i=1;i<=K;i++){
				ans=(ans+fac[n-2])%MOD;
				if(n>=3)ans=(ans-fac[n-3]*1ll*(i-1)%MOD+MOD)%MOD;
			}
			printf("%lld\n",ans);
			continue;
		}
		long long tmp=0;
		for(int i=1;i<=K;i++){
			ans=1;
			dfs(sx[p[i]],sy[p[i]]);
			dfs(sy[p[i]],sx[p[i]]);
			tmp=(tmp+ans)%MOD;
		}
		printf("%lld\n",tmp);
	}
}
