//I hate countings!
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll inv2=500000004,mod=1e9+7;
int read()
{
	char ch=getchar();int cna=0;
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')cna=cna*10+ch-'0',ch=getchar();
	return cna;
}
ll qp(ll x,ll y)
{
	ll s=1,base=x;
	while(y)
	{
		if(y&1)s=s*base%mod;
		base=base*base%mod;y>>=1;
	}
	return s;
}
int C,T;
int n,k;
int ax[100003],ay[100003];
int head[100003],to[200003],nt[200003],tot=0;
int e[100003];
void add(int x,int y){to[++tot]=y;nt[tot]=head[x];head[x]=tot;}
void clear()
{
	for(int i=1;i<=n;i++)head[i]=0;
	for(int i=1;i<=tot;i++)nt[i]=0;
	tot=0;
}
ll jc[100003];
namespace kone
{
	int rt;
	ll f[100003];
	int fa[100003];
	void dfs(int x)
	{
		int s=0;f[x]=1;
		for(int i=head[x];i;i=nt[i])
		{
			int y=to[i];
			if(fa[x]==y)continue;
			fa[y]=x;++s;
			dfs(y);
			f[x]=f[x]*f[y]%mod;
		}
		if(s>1)f[x]=f[x]*jc[s]%mod;
		if(x==rt)
		{
			f[x]=f[x]*qp(s,mod-2)%mod;
			printf("%lld\n",f[x]);
		}
	}
	void solve()
	{
		rt=ax[e[1]];
		for(int i=1;i<=n;i++)fa[i]=0;
		dfs(rt);
	}
}
namespace B
{
	void solve()
	{
		ll ans1=0,ans2=0;
		ans1=1ll*k*(n-1-k)%mod*jc[n-1-2]%mod;
		ans2=1ll*k*(k-1)%mod*jc[n-1-2]%mod;
		printf("%lld\n",(ans1+ans2*inv2)%mod);
	}
}
void solve()
{
	n=read(),k=read();
	int B=0,A=0;
	for(int i=1;i<n;i++)ax[i]=read(),ay[i]=read(),add(ax[i],ay[i]),add(ay[i],ax[i]),B|=(ax[i]!=1),A|=(ax[i]!=i||ay[i]!=i+1);
	for(int i=1;i<=k;i++)e[i]=read();
	if(k==1){kone::solve();clear();return;}
	if(!B){B::solve();clear();return;}
	if(!A){printf("1\n");clear();return;}
}
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	jc[0]=1;
	for(int i=1;i<=100000;i++)jc[i]=jc[i-1]*i%mod;
	C=read(),T=read();
	while(T--)solve();
	return 0;
}
