#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=1e6+10;
const int INF=0x3f3f3f3f;
const LL p=1e9+7 ;
int read()
{
	char ch=getchar();
	int f=1,num=0;
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		num=(num<<1)+(num<<3)+ch-'0';
		ch=getchar();
	}
	return f*num;
}
int c,t,n,k;
vector<int> g[N],idx[N]; 
int U[N],V[N],e[N];
int vis[N];
LL num[N];
int ne[N];
LL fac[N];
void dfs(int u)
{
	int cnt=0;
	for(int i =0;i<g[U[u]].size();i++)
	{
		int v=idx[U[u]][i];
		if(vis[v])
			continue;
		vis[v]=u,cnt++;
	}
	LL res1=1ll;
	for(int i =0;i<g[U[u]].size();i++)
	{
		int v=idx[U[u]][i];
		if(vis[v]!=u)
			continue;
		dfs(v);
		res1=res1*num[v]%p;
	}
	res1=res1*fac[cnt]%p;
	cnt=0;
	for(int i =0;i<g[V[u]].size();i++)
	{
		int v=idx[V[u]][i];
		if(vis[v])
			continue;
		vis[v]=u,cnt++;
	}
	LL res2=1ll;
	for(int i =0;i<g[V[u]].size();i++)
	{
		int v=idx[V[u]][i];
		if(vis[v]!=u)
			continue;
		dfs(v);
		res2=res2*num[v]%p;
	}
	res2=res2*fac[cnt]%p;
//	printf("\n%d\n",res2);
	num[u]=res1*res2%p;
//	printf("%d %d\n",u,num[u]);
}
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	c=read(),t=read();
	fac[0]=1;
	for(int i = 1;i<=100000;i++)
		fac[i]=fac[i-1]*i%p;
	while(t--)
	{
		n=read(),k=read();
		for(int i = 1;i<=n;i++)
			g[i].clear(),idx[i].clear();
		for(int i = 1;i<n;i++)
		{
			U[i]=read(),V[i]=read();
			g[U[i]].push_back(V[i]);
			g[V[i]].push_back(U[i]);
			idx[U[i]].push_back(i);
			idx[V[i]].push_back(i);
		}
		for(int i = 1;i<=k;i++)
			e[i]=read();
		if(c==18)
		{
			puts("1");
			continue;
		}
		if(c>=19&&c<=21)
		{
			printf("%lld\n",(k*fac[n-3]%p*(n-k-1)%p+k*(k-1)/2%p*fac[n-3]%p)%p);
			continue;
		}
		if(k==1)
		{
			LL res=0;
			for(int i = 1;i<=k;i++)
			{
				for(int j = 1;j<n;j++)
					vis[j]=0,num[j]=1ll;
				vis[e[i]]=-1;
//				printf("%d\n",e[i]);
				dfs(e[i]);
				res=(res+num[e[i]])%p;
			}
			printf("%lld\n",res);
		}
	}
}
//19 1
//4 2
//1 2
//1 3
//1 4
//1 2
