#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,mod=1e9+7,iv2=(mod+1)/2;
int read(){int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	return x*f; 
}
int ty,n,k,a[N],t[N];
struct node{int u,v;}e[N];
void solve(){int tot=0,jc=1;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)t[i]=0;
	for(int i=1;i<=n-3;i++)jc=1ll*jc*i%mod;
	for(int i=1,x,y;i<n;i++)x=read(),y=read(),e[i]={x,y};
	for(int i=1,x;i<=k;i++){
		scanf("%d",&a[i]);
		tot+=!t[a[i]],t[a[i]]=1;
	}
	
	if(ty==18)puts("1");
	else {
		int sum=1ll*tot*(tot-1)/2%mod+1ll*tot*(n-1-tot)%mod;
		sum%=mod; 
		if(n>2)printf("%d\n",1ll*sum*jc%mod);
		else if(n==2)puts("1");
	}
}
int main(){int T;
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%d%d",&ty,&T);
	while(T--)solve();
	return 0;
}

