#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int c,t,n,k,ans;
int d[100016],f[100016],e[100016];
int read()
{
	int w=0,f=1;
	char c=getchar();
	while(c<'0' || c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0' && c<='9')
	{
		w=(w<<3)+(w<<1)+c-'0';
		c=getchar();
	}
	return w*f;
}
void init()
{
	f[0]=1;
	for(int i=1;i<=100015;i++)
	{
		f[i]=f[i-1]*i%mod;
	}
}
signed main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout); 
	c=read(),t=read();
	init();
	while(t--)
	{
		n=read(),k=read();
		memset(d,0,sizeof(d));
		ans=1;
		for(int i=1;i<n;i++)
		{
			int u,v;
			u=read();
			v=read();
			d[u]++;
			d[v]++;
		}
		for(int i=1;i<=k;i++)
		{
			e[i]=read();
		}
		if(k==1)
		{
			for(int i=1;i<=n;i++)
			{
				if(d[i]==1 || d[i]==2 || d[i]==0) continue;
				ans=(ans*f[d[i]-1])%mod;
			}
			cout<<ans<<endl;
		}
		if(c==18) cout<<1<<endl;
		if(c==19 || c==20 || c==21)
		{
			for(int i=1;i<=n;i++)
			{
				if(d[i]==1 || d[i]==2 || d[i]==0) continue;
				ans=(ans*f[d[i]-1])%mod;
			}
			cout<<ans<<endl;
		}
	}
}
