#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=1e5+5,P=1e9+7;
int ID,T,n,k,in[N],jc[N],u[N],v[N],res,vs[N],inv[N],fa[N],ans,c[N],a[N];
vector<pair<int,int>>g[N];
inline int read()
{
	int s=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')
		ch=getchar();
	while(ch>='0'&&ch<='9')
		s=s*10+ch-48,ch=getchar();
	return s;
}
void dfs(int x,int y)
{
	fa[x]=y;
	for(auto v:g[x])
		if(v.fi^y)
			dfs(v.fi,x);
}
void sou(int x,int y,int t,int p)
{
	if(g[x].size()==1&&t)
		(ans+=p)%=P;
	p=1LL*p*inv[g[x].size()-1]%P;
	for(auto v:g[x])
		if(v.fi^y)
			sou(v.fi,x,t|c[v.se],p);
}
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%d%d",&ID,&T);
	for(int i=jc[0]=inv[1]=inv[0]=1;i<N;i++)
		jc[i]=jc[i-1]*1LL*i%P;
	for(int i=2;i<N;i++)
		inv[i]=1LL*(P-P/i)*inv[P%i]%P;
	while(T--)
	{
		scanf("%d%d",&n,&k);
		if(n==2)
		{
			puts("1");
			continue;
		}
		for(int i=1;i<=n;i++)
			g[i].clear(),c[i]=0;
		for(int i=1;i<n;i++)
			g[u[i]=read()].emplace_back(v[i]=read(),i),g[v[i]].emplace_back(u[i],i);
		for(int i=1;i<=k;i++)
			c[a[i]=read()]=1;
		if(ID==18)
		{
			puts("1");
			continue;
		}
		res=1,ans=0;
		for(int i=1;i<=n;i++)
			res=1LL*res*jc[g[i].size()-1]%P;
		if(k==1)
		{
			printf("%d\n",res);
			continue;
		}
		if(ID>=19&&ID<=21)
		{
			printf("%lld\n",(1LL*k*jc[n-2]%P+P-k*(k-1LL)/2%P*jc[n-3]%P)%P);
			continue;
		}
		for(int i=1;i<=n;i++)
			if(g[i].size()==1)
				sou(i,0,0,1);
		printf("%lld\n",1LL*ans*res%P*(P+1>>1)%P);
	}
}
