#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL N=1e5+10,P=1e9+7;
LL n,m,deg[N],fac[N],id[N],f[N],cnt[N];
struct edge { LL u,v; }e[N];
LL ksm(LL a,LL b) { LL res=1; for(;b;b>>=1,a=a*a%P) if(b&1) res=res*a%P; return res; }
bool cmp(LL a,LL b) { return min(deg[e[a].u],deg[e[a].v])<min(deg[e[b].u],deg[e[b].v]); }
void solve()
{
	for(int i=1;i<=n;i++) deg[i]=cnt[i]=0;
	scanf("%lld%lld",&n,&m);
	fac[0]=1;
	for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%P;
	for(int i=1;i<n;i++)
	{
		LL u,v;
		scanf("%lld%lld",&u,&v);
		deg[u]++; deg[v]++;
		e[i]=(edge){u,v};
	}
	LL zxz=1,ans=0;
	for(int i=1;i<=n;i++) f[i]=fac[deg[i]-1],zxz=zxz*f[i]%P;
	for(int i=1;i<=m;i++) scanf("%lld",id+i);
	sort(id+1,id+m+1,cmp);
	for(int i=1;i<=m;i++)
	{
		ans=(ans+zxz)%P;
		LL u=e[id[i]].u,v=e[id[i]].v;
		if(deg[u]==1||deg[v]==1)
		{
			if(deg[v]==1) swap(u,v);
			zxz=zxz*ksm(f[v],P-2)%P;
			cnt[v]++;
			f[v]=fac[deg[v]-2]*(deg[v]-1-cnt[v])%P;
			zxz=zxz*f[v]%P;
		}
	}
	printf("%lld\n",ans);
}
int main()
{
//	system("fc traverse.out traverse4.ans");
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	LL c,t;
	scanf("%lld%lld",&c,&t);
	while(t--) solve();
	return 0;
}
