#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5,mod = 1e9 + 7;
int c,T,n,k,ans,inv[N],fac[N],ifac[N],mi[N],vis[N],f[N],c1[N],c2[N];
vector <pair <int,int>> v[N];
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	fac[0] = 1;
	for(int i = 1;i <= 100000;i++) fac[i] = 1LL * fac[i - 1] * i % mod;
	scanf("%d%d",&c,&T);
	while(T--)
	{
		scanf("%d%d",&n,&k);
		for(int i = 1;i <= n;i++) v[i].clear(),vis[i] = 0;
		for(int i = 1,a,b;i < n;i++)
		{
			scanf("%d%d",&a,&b);
			v[a].push_back(make_pair(b,i));
			v[b].push_back(make_pair(a,i));
		}
		for(int i = 1,e;i <= k;i++)
		{
			scanf("%d",&e);
			vis[e] = 1;
		}
		if(c <= 6)
		{
			ans = 1;
			for(int i = 1;i <= n;i++) ans = 1LL * ans * fac[v[i].size() - 1] % mod;
			printf("%d\n",ans);
			continue;
		}
		if(c == 18)
		{
			puts("1");
			continue;
		}
		if(n <= 2)
		{
			puts("1");
			continue;
		}
		ans = 0;
		for(int i = 1;i <= k;i++) ans = (ans + 1LL * (n - 1 - i) * fac[n - 3] % mod) % mod;
		printf("%d\n",ans);
	}
	return 0;
}
