#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define int long long
#define mod 1000000007ll
using namespace std;
int read()
{
	int ans=0,fl=1;
	char c=getchar();
	while ((c<'0'||c>'9')&&c!='-') c=getchar();
	if (c=='-')
	{
		c=getchar();
		fl=-1;
	}
	while (c>='0'&&c<='9')
	{
		ans=ans*10+c-48;
		c=getchar();
	}
	return ans*fl;
}
int T,n,k,d[100005],tot,cnt[100005];
pair<int,int> ed[100005];
int cz;
int head[100005],to[200005],nxt[200005],lst[200005];
void del(int x,int y)
{
	if (nxt[x]) lst[nxt[x]]=lst[x];
	if (lst[x]) nxt[lst[x]]=nxt[x];
	if (x==head[y]) head[y]=nxt[x];
	return;
}
void add(int x,int y)
{
	to[++tot]=y;
	nxt[tot]=head[x];
	if (head[x]) lst[head[x]]=tot;
	head[x]=tot;
	return;
}
bool vis[100005];
int cq[100005];
void dfs(int x,int fa)
{
	for (int i=head[x];i;i=nxt[i])
	{
		if (to[i]==fa) continue;
		del(i,x);
		++cnt[to[i]];
		if (!vis[to[i]]) cq[++cz]=to[i];
		vis[to[i]]=1;
		dfs(to[i],x);
	}
	return;
}
int fac[100005],V[100005],SV;
int gt(int sz,int m)
{
	return (fac[sz-1]*m%mod-m*(m-1)%mod*500000004ll%mod*fac[sz-2]%mod+mod)%mod;
}
int ksm(int x,int y)
{
	int ans=1;
	while (y)
	{
		if (y&1) ans=ans*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return ans;
}
signed main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int opt=read();
	T=read();
	fac[0]=1;
	for (int i=1;i<=100000;i++) fac[i]=fac[i-1]*i%mod;
	while (T--)
	{
		n=read();
		k=read();
		for (int i=1;i<=tot;i++) nxt[i]=lst[i]=0;
		tot=0;
		for (int i=1;i<=n;i++)
		{
			d[i]=0;
			cnt[i]=0;
			head[i]=0;
			vis[i]=0;
		}
		SV=1;
		for (int i=1;i<n;i++)
		{
			ed[i].first=read(),ed[i].second=read();
			d[ed[i].first]++;
			d[ed[i].second]++;
			add(ed[i].first,ed[i].second);
			add(ed[i].second,ed[i].first);
		}
		for (int i=1;i<=n;i++)
		{
			if (d[i]!=1) V[i]=gt(d[i],1);
			if (d[i]!=1) SV=SV*V[i]%mod;
		}
		int ans=0;
		for (int i=1;i<=k;i++)
		{
			int wh=read(),sv=SV,vc=1;
			dfs(ed[wh].first,0);
			dfs(ed[wh].second,0);
			while (cz)
			{
				vis[cq[cz]]=0;
				if (d[cq[cz]]!=1)
				{
					sv=sv*ksm(V[cq[cz]],mod-2)%mod;
					vc=vc*(fac[d[cq[cz]]-2]*(cnt[cq[cz]]-1)%mod)%mod;
				}
				cz--;
			}
			ans=(ans+SV-sv*vc%mod+mod)%mod;
		}
		printf("%lld\n",ans);
	}
	return 0;
}
