#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=(ll)1e9+7;
ll n,m,k,z,x,s,ct,tz,a[100005],ans,y,fc[100005];
ll eg[100005][2],dep[100005],sn[100005],f[100005];
int em,lt[100005],nx[1000005],e[1000005];
long long read(){
	char ch=getchar();
	long long ip=1,xx=0;
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-'){
		ip=-1,ch=getchar();
		while(ch<'0'||ch>'9') ch=getchar();
	}
	while(ch>='0'&&ch<='9')
		xx=xx*10+ch-'0',ch=getchar();
	return xx*ip;
}
void in(int xx,int yy){
	e[++em]=yy,nx[em]=lt[xx],lt[xx]=em;
	return ;
}
void dfs(int xx,int fa){
	dep[xx]=dep[fa]+1;
	for(int i=lt[xx];i!=0;i=nx[i]){
		if(e[i]==fa) continue;
		sn[xx]++;
		dfs(e[i],xx);
	}
	return ;
}
void dp(int xx,int fa){
	for(int i=lt[xx];i!=0;i=nx[i]){
		if(e[i]==fa) continue;
		dp(e[i],xx);
		if(xx!=eg[a[1]][0]||e[i]!=eg[a[1]][1])
			f[xx]=f[xx]*f[e[i]]%mod;
	}
	if(xx==eg[a[1]][0]) sn[xx]--;
	if(sn[xx]>1) f[xx]=f[xx]*fc[sn[xx]]%mod;
	return ;
}
int main(){
	//traverse
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	fc[0]=1;
	for(ll i=1;i<=100000;i++)
		fc[i]=fc[i-1]*i%mod;
	ct=read(),tz=read();
	while(tz--){
		n=read(),k=read();
		for(int i=1;i<=n;i++) lt[i]=0,dep[i]=0,f[i]=1,sn[i]=0;
		for(int i=1;i<=em;i++) nx[i]=0,e[i]=0;
		em=0;
		for(int i=1;i<n;i++){
			eg[i][0]=read(),eg[i][1]=read();
			in(eg[i][0],eg[i][1]),in(eg[i][1],eg[i][0]);
		}
		for(int i=1;i<=k;i++)
			a[i]=read();
		if(k==1){
			ans=0;
			dfs(eg[a[1]][0],0);
			dp(eg[a[1]][0],0);
			ans=f[eg[a[1]][0]]*f[eg[a[1]][1]]%mod;
			printf("%lld\n",ans);
		}
		else if(ct==18)
			printf("1\n");
		else{
			ans=0,n--;
			for(int i=1;i<=k;i++){
				ans=(ans+(n-i)*fc[n-2])%mod;
			}
			printf("%lld\n",ans);
		}
	}
	return 0;
}
