#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=2e5+10;
const ll modd=1e9+7;
int C,T;
int n,K;
struct Edge
{
	int ev,enex;
}e[maxn<<1];
int head[maxn],tote=0;
ll ans=1;
bool ve[maxn];
int pw[maxn],dp[maxn];
void init()
{
	tote=0,ans=1;
	for(int i=1;i<=n;i++)	head[i]=0,ve[i]=0,dp[i]=0;
}
void dfs2(int x,int Fa)
{
	for(int i=head[x],y;i;i=e[i].enex)
	{
		y=e[i].ev;
		if(y==Fa)	continue;
		dfs2(y,x);
	}
	return ;
}
void dfs1(int x,int Fa)
{
	//printf("%d\n",x);
	ll sn=0,sm=0;
	for(int i=head[x],y;i;i=e[i].enex)
	{
		y=e[i].ev;
		if(y==Fa)	continue;
		dfs1(y,x);
		if(ve[(i+1)>>1])	dp[y]++;
		//printf("%d %d %d\n",x,y,dp[y]);
		if(dp[y])	sn++;
		else	sm++;
		dp[x]+=dp[y];
	}
	if(x!=1)
	{
		if(K-dp[x])	sn++;
		else	sm++;
	}
	//printf("x: %d %lld %lld\n",x,sn,sm);
	if(sn+sm<2)	return ;
	ans*=((sn*sm%modd+(sn*(sn-1)/2)%modd)%modd)*(ll)pw[sn+sm-2]%modd;
	ans%=modd;
	return ;
}
//int du[maxn];
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("tarverse.out","w",stdout);
	scanf("%d%d",&C,&T);
	pw[0]=1;
	for(int i=1;i<=100000;i++)	pw[i]=((ll)pw[i-1]*(ll)i)%modd;
	for(int t=1;t<=T;t++)
	{
		scanf("%d%d",&n,&K);
		//printf("%d %d\n",n,K);
		for(int i=1,u,v;i<=n-1;i++)
		{
			scanf("%d%d",&u,&v);
			//du[u]++,du[v]++;
			e[++tote].ev=v,e[tote].enex=head[u],head[u]=tote;
			e[++tote].ev=u,e[tote].enex=head[v],head[v]=tote;
		}
		for(int i=1,x;i<=K;i++)
		{
			scanf("%d",&x);ve[x]=1;
		}
		//printf("%d %d\n",n,K);
		//if(t!=1) dfs2(1,0);
		//printf("ok\n");
		dfs1(1,0);
		printf("%lld\n",ans); 
		init();
	}
	return 0;
}
