#include<cstdio>
#include<algorithm>
typedef long long ll;
const int N(1e5+5);
int e[N],eg[N][5],in[N];
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	ll C,T,n,k,u,v,te,cnt,ans,i;
	for(scanf("%lld %lld",&C,&T);T--;)
	{
		scanf("%lld %lld",&n,&k);
		for(i=1;i<=n;i++)
		  e[i]=eg[i][1]=eg[i][2]=in[i]=0;
		for(i=1;i<n;i++)
		  scanf("%lld %lld",&u,&v),
		  in[u]++,in[v]++,eg[i][1]=u,eg[i][2]=v;
		for(i=1;i<=k;i++)
		  scanf("%lld",e+k);
		if(k==1)
		{
			te=e[1],cnt=0,ans=1;
			for(i=1;i<=n;i++)
			  cnt+=int(in[i]==1);
			if(in[eg[1][1]]==1||in[eg[1][2]]==1)
			  cnt--;
			for(i=2;i<=cnt;i++)
			  (ans*=i)%=1000000007;
			printf("%lld\n",ans);
			continue;
		}
		printf("%d\n",rand());
	}
	return ~~(0-0);
}
