#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=4e5+5,mod=1e9+7;
int n,k,tot,vis[N],cnt[N],d[N],to[N],p[N],head[N],bl[N],U[N],V[N],ID[N],ans=1;
int c,t,jc[N],ny[N];
int tp[N],fa[N],l,r,deg[N];
void add(int u,int v)
{
	p[++tot]=v,to[tot]=head[u],head[u]=tot;
}
int poww(int x,int p)
{
	int y=1;
	while(p)
	{
		if(p&1)y=y*x%mod;
		x=x*x%mod;
		p/=2;
	}
	return y;
}
void dfs(int u)
{
	for(int i=head[u];i;i=to[i])
	{
		int v=p[i];
		if(v!=fa[u])fa[v]=u,dfs(v);
	}
}
int C(int n,int m)
{
	if(n>m)return 0;
	return jc[m]*ny[n]*ny[m-n];
}
void clear()
{
	for(int i=1;i<=n;i++)vis[i]=cnt[i]=d[i]=bl[i]=head[i]=fa[i]=deg[i]=0;
	tot=r=0;
	ans=l=1;
}
signed main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%lld%lld",&c,&t);
	jc[0]=1;
	for(int i=1;i<=N-5;i++)jc[i]=jc[i-1]*i%mod;
	ny[N-5]=poww(jc[N-5],mod-2);
	for(int i=N-6;i>=0;i--)ny[i]=ny[i+1]*(i+1)%mod;
	while(t--)
	{
		scanf("%lld%lld",&n,&k);
		for(int i=1;i<n;i++)
		{
			int u,v;
			scanf("%lld%lld",&u,&v);
			add(u,v),add(v,u);
			d[u]++,d[v]++;
			U[i]=u,V[i]=v;
		}
		for(int i=1;i<=k;i++)
		{
			int id;
			scanf("%lld",&id);
			ID[i]=id;
			bl[U[id]]=bl[V[id]]=1;
		}
		dfs(U[ID[1]]);
		for(int i=1;i<=n;i++)deg[fa[i]]++,cnt[i]=d[i];
		for(int i=1;i<=n;i++)if(deg[i]==0&&bl[i]==0)tp[++r]=i;
		while(l<=r)
		{
			int u=tp[l++];
			cnt[fa[u]]--;
			deg[fa[u]]--;
			if(deg[fa[u]]==0&&bl[fa[u]]==0)tp[++r]=fa[u];
		}
		for(int i=1;i<=n;i++)ans=ans*((jc[d[i]-1]*cnt[i]%mod-jc[d[i]-2]*C(2,cnt[i])%mod+mod)%mod)%mod;
		printf("%lld\n",ans);
		clear();
	}
}
/*
1 1
4 1
1 2
2 3
2 4
1

7 1
5 2
1 2
1 3
2 4
2 5 
1 3
*/
