#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5,mod=1e9+7;
int c,T,n,k,u[N],v[N],t,d[N],ans;
bool vis[N];
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;
}
int tot,ver[2*N],ne[2*N],head[N],val[2*N];
void add(int u,int v,int w)
{
	ver[++tot]=v;
	ne[tot]=head[u];
	head[u]=tot;
	val[tot]=w;
}
void dfs(int x,int fa,int sum)
{
	for(int i=head[x];i;i=ne[i])
	{
		int y=ver[i];
		if(y==fa) continue;
		if(!vis[x])
		{
			vis[x]=1;
			sum-=d[fa];
			ans=ans*(sum+d[y]-1);
		}
		dfs(y,x,sum+d[y]-1);
	}
}
signed main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	c=read();T=read();
	while(T--)
	{
		n=read();k=read();tot=0;ans=1;
		memset(d,0,sizeof d);
		memset(head,0,sizeof head);
		memset(vis,0,sizeof vis);
		for(int i=1;i<n;i++)
		{
			u[i]=read();v[i]=read();
			add(u[i],v[i],i);add(v[i],u[i],i);
			d[u[i]]++;d[v[i]]++;
		}
		while(k--)
		{
			t=read();ans=ans*(d[u[t]]+d[v[t]]-2)%mod;
			if(d[u[t]]>1) dfs(u[t],v[t],d[u[t]]+d[v[t]]-2);
			if(d[v[t]]>1) dfs(v[t],u[t],d[u[t]]+d[v[t]]-2);
		}
		printf("%lld\n",ans);
	}
}
