#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
const long long N=1e5+9;
long long read()
{
	long long ans=0;
	char c=getchar();
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9')
	ans=(ans<<1)+(ans<<3)+c-'0',c=getchar();
	return ans;
}
long long pd1,pd2,pd3,t,n,k,c,h[N],lp,ans;
struct dd
{
	long long x,to;
}cc[2*N];
bool bl[N*2];
long long jc[N],zg;
void build(int x,int y)
{
	zg++;
	cc[zg].to=y;
	cc[zg].x=h[x];
	h[x]=zg;
}
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	c=read(),t=read();
	jc[0]=1;
	for(long long i=1;i<=N-5;i++)
	jc[i]=jc[i-1]*i,jc[i]%=mod;
	while(t)
	{
		t--;
		n=read(),k=read();
		lp=0,ans=0;
		pd2=pd3=0;
		zg=0;
		memset(h,0,sizeof(h));
		for(long long i=1,u,v;i<=n-1;i++)
		{
			u=read(),v=read();
			if(u==v-1)
			pd2++;
			if(u==1)
			pd3++;
			build(u,v);
			build(v,u);
		}
		for(long long i=1,l;i<=k;i++)
		{
			l=read();
		}
		if(pd2==n-1)
		cout<<1<<endl;
		else if(pd3==n-1)
		{
			ans=jc[n-2]*k;
			lp=k*(k-1)/2;
			lp=lp%mod;
			lp*=jc[n-3];
			lp=lp%mod;
			ans=ans%mod;
			ans=ans-lp;
			ans=(ans+mod)%mod;
			cout<<ans<<endl;
		}
		else
		cout<<ans<<endl;
	}
}
