#include<bits/stdc++.h>
#define Yukinoshita namespace
#define Yukino std
using Yukinoshita Yukino;
int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') w=ch=='-'?-1:1,ch=getchar();
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
const int mxn=1e5+5;
const int mod=1e9+7;
pair<int,int> e[mxn];
int fac[mxn],deg[mxn],deg2[mxn];
vector<int> t[mxn];
int id[mxn];
vector<int> ovo;
bool ok;
void dfs(int d,int fa)
{
//	cout<<d<<endl;
	ovo.push_back(d);
	if(!ok&&(d==e[id[2]].first||d==e[id[2]].second))
	{
		ok=1;
		for(auto x:ovo)
			deg[x]--;
	}
	for(auto x:t[d])
		if(x!=fa)
			dfs(x,d);
	ovo.pop_back();	
}
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int c=read(),T=read();
	while(T--)
	{
		ok=0;
		int n=read(),k=read(),i;
		memset(deg,0,n+1<<2);
		fac[0]=1;
		for(i=1;i<=n;i++)
			fac[i]=1ll*fac[i-1]*i%mod;
		for(i=1;i<=n;i++)
			t[i].clear();
		for(i=1;i<n;i++)
		{
			int x=read(),y=read();
			e[i]=make_pair(x,y);
			deg[x]++,deg[y]++;
			t[x].push_back(y);
			t[y].push_back(x);
		}
		int mul=1;
		for(i=1;i<=k;i++)
			id[i]=read();
		if(n==2)
		{
			puts("1");
			continue;
		}
		bool fl=0;
		for(i=1;i<=n;i++)
			fl|=deg[i]==n-1;
		if(fl)
		{
			printf("%d\n",(1ll*fac[n-2]*k-1ll*k*(k-1)/2%mod*fac[n-3]%mod+mod)%mod);
			continue;
		}
		for(i=1;i<=n;i++)
			mul=1ll*mul*fac[deg[i]-1]%mod;	
		if(k==2)
		{
			mul=mul*2%mod;
			ok=0;
			dfs(e[id[1]].first,e[id[1]].second);
			dfs(e[id[1]].second,e[id[1]].first);
			int mul2=1;
			for(i=1;i<=n;i++)
				if(deg[i])
					mul2=1ll*mul2*fac[deg[i]-1]%mod;
			mul=(mul-mul2+mod)%mod;
		}
//		cout<<k<<endl;
		
		printf("%d\n",mul);
	}
}
