#include <bits/stdc++.h>
#define Code using
#define by namespace
#define zzx std
#define mod 1000000007
Code by zzx;
int C, T;
int n, k, E[100010][2];
long long f[100010];
vector<int> e[100010];
void init()
{
	f[0] = 1;
	for(long long i = 1; i <= 100000; ++i)
	{
		f[i] = f[i - 1] * i % mod;
	}
}
long long dfs(int l, int u)
{
	long long res = 1, cnt = 0;
	for(int i = 0; i < e[u].size(); ++i)
	{
		int v = e[u][i];
		if(v == l)
		{
			continue;
		}
		++cnt;
		res = res * dfs(u, v) % mod;
	}
	res = res * f[cnt] % mod;
	return res;
}
int main()
{
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	scanf("%d %d", &C, &T);
	init();
	while(T--)
	{
		scanf("%d %d", &n, &k);
		for(int i = 1; i <= n; ++i)
		{
			e[i].clear();
		}
		for(int i = 1; i < n; ++i)
		{
			int u, v;
			scanf("%d %d", &u, &v);
			e[u].push_back(v);
			e[v].push_back(u);
			E[i][0] = u;
			E[i][1] = v;
		}
		if(k == 1)
		{
			int p;
			scanf("%d", &p);
			int x = E[p][0], y = E[p][1];
			long long ans = dfs(x, y) * dfs(y, x);
			if(e[x].size() > 1 && e[y].size() > 1)
			{
				ans = ans * 2 % mod;
			}
			printf("%lld\n", ans);
		}	
		else
		{
			for(int i = 1; i <= k; ++i)
			{
				int p;
				scanf("%d", &p);
			}
			printf("1\n");
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
