#include<cstdio>
using namespace std;
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fe(i,a,b) for(int i=a;i>=b;--i)
#define ll long long
const int N=1e5+5,M=1e9+7;
int ID,T,n,k,head[N],nxt[N<<1],to[N<<1],cnt,du[N],d[N],c[N],f[N];
void ins(int u,int v){nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v,++du[v];}
void dfs(int u,int fa)
{
	f[u]=c[du[u]-1];
	for(int i=head[u];i;i=nxt[i])
	{
		int v=to[i];
		if(v!=fa) dfs(v,u),f[u]=(ll)f[u]*f[v]%M;
	}
}
int read()
{
	int s=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s;
}
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%d%d",&ID,&T);
	while(T--)
	{
		scanf("%d%d",&n,&k),cnt=c[0]=1;
		fo(i,1,n) head[i]=f[i]=du[i]=0,c[i]=(ll)c[i-1]*i%M;
		fo(i,1,n-1)
		{
			int u=read(),v=read();
			ins(u,v),ins(v,u);
		}
		fo(i,1,k) d[i]=read();
		if(k==1)
		{
			dfs(to[d[1]<<1],to[d[1]<<1|1]),dfs(to[d[1]<<1|1],to[d[1]<<1]),printf("%lld\n",(ll)f[to[d[1]<<1]]*f[to[d[1]<<1|1]]%M);
			continue;
		}
		printf("%d\n",k);
	}
	return 0;
}
