#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define fre(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
using namespace std;
#define int long long
void read(int &x)
{
	x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
}
void write(int x)
{
	if(x<10)putchar(x+'0');
	else write(x/10),putchar(x%10+'0');
}
const int N=2e5+10,mod=1e9+7;
int c,t,n,k,d[N],s[N],cnt[N];
long long fac[N],ans;
vector<int> g[N];
int get(int x,int y)
{
	return (y*(y-1)/2)%mod*fac[x-2]%mod;
}
void dfs(int x,int fa)
{
	for(int v:g[x])
	{
		if(v!=fa)
		{
			dfs(v,x);
			s[x]+=s[v];
			if(x>n&&s[v]>0)cnt[x]++;
		}
	}
	if(x>n&&k-s[x]>0)cnt[x]++;
	if(x>n)ans=ans*((fac[d[x]-1]*cnt[x]%mod-get(d[x],cnt[x])+mod)%mod)%mod;
}
signed main()
{
	fre("traverse");
	fac[0]=1;for(int i=1;i<N;i++)fac[i]=fac[i-1]*i%mod;
	read(c),read(t);
	while(t--)
	{
		ans=1;
		read(n),read(k);
		for(int i=1;i<=n*2;i++)g[i].clear(),d[i]=s[i]=cnt[i]=0;
		for(int i=1;i<n;i++)
		{
			int x,y;
			read(x),read(y);
			x+=n,y+=n;
			g[x].push_back(i);
			g[i].push_back(x);
			g[y].push_back(i);
			g[i].push_back(y);
			d[x]++,d[y]++;
		}
		for(int i=1,x;i<=k;i++)read(x),s[x]++;
		dfs(1,0);
		printf("%lld\n",ans);
	}
}