#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5,M=1e9+7;
struct Date{
	int x,y;
};Date a[N];
long long F[N],G[N],f[N],g[N],h[N],ans;
int tot,he[N],ne[N*2],to[N*2],s[N],que[N];
long long Pow(long long x,int y)
{
	long long pre=1;
	while(y>0)
	{
		if((y&1)==1)
		pre=pre*x%M;
		x=x*x%M;y=y>>1;
	}
	return pre;
}
int read()
{
	int s=0;char ch=getchar();
	while(ch<'0'||ch>'9')
	ch=getchar();
	while(ch>='0'&&ch<='9')
	{
		s=(s<<3)+(s<<1)+int(ch-'0');
		ch=getchar();
	}
	return s;
}
void dfs(int x,int fa)
{
	int i,y;s[x]=0;
	for(i=he[x];i!=0;i=ne[i])
	{
		y=to[i];
		if(y!=fa)
		{
			dfs(y,x);s[x]++;f[x]=f[x]*f[y]%M;
		}
	}
	f[x]=f[x]*g[s[x]]%M;
}
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int T,id,n,m,i,j,x,y;long long p1,p2;
	id=read();T=read();
	n=1e5;F[0]=G[0]=1;
	for(i=1;i<=n;i++)
	F[i]=F[i-1]*i%M;
	G[n]=Pow(F[n],M-2);
	for(i=n-1;i>=1;i--)
	G[i]=G[i+1]*(i+1)%M;
	n=500;g[0]=1;h[0]=1;
	for(i=1;i<=n;i++)
	{
		for(j=0;j<i;j++)
		{
			p1=F[i-1]*(G[j]*G[i-1-j]%M)%M;p2=g[j]*h[i-1-j]%M;
			g[i]=(g[i]+p1*p2)%M;
		}
		for(j=0;j<=i;j++)
		{
			p1=g[j]*g[i-j]%M;p2=F[i]*(G[j-i]*G[j]%M)%M;
			h[i]=(h[i]+p1*p2)%M;
		}
	}
	while(T>0)
	{
		T--;tot=0;ans=0;
		n=read();m=read();
		for(i=1;i<=n;i++)
		he[i]=0;
		for(i=1;i<n;i++)
		{
			a[i].x=x=read();a[i].y=y=read();
			tot++;ne[tot]=he[x];to[tot]=y;he[x]=tot;
			tot++;ne[tot]=he[y];to[tot]=x;he[y]=tot;
		}
		for(i=1;i<=m;i++)
		que[i]=read();
		if(id==18)
		{
			printf("1\n");continue;
		}
		if(id>=19&&id<=21)
		{
			printf("%lld\n",F[n-1]);continue;
		}
		for(i=1;i<=m;i++)
		{
			j=que[i];x=a[j].x;y=a[j].y;
			for(j=1;j<=n;j++)
			f[j]=1;
			dfs(x,y);dfs(y,x);
			p1=1;
			for(j=he[x];j!=0;j=ne[j])
			{
				if(to[j]!=y)
				p1=p1*f[to[j]]%M;
			}
			ans=(ans+p1*g[s[x]+s[y]])%M;
		}
		printf("%lld\n",ans);
	}
	return 0;
}
