#include <bits/stdc++.h>
#define int long long
#define debug(x) cerr << #x << ": " << x << endl
using namespace std;

const int MAXN = 1e5 + 7, mod = 1e9 + 7;
int vis[MAXN], fac[MAXN];

vector<int> to[MAXN];
pair<int, int> bian[MAXN];

int qpow(int u, int v)
{
	int res = 1;
	while (v)
	{
		if (v & 1) res = res * u % mod;
		u = u * u % mod;
		v >>= 1;
	}
	return res;
}

signed main()
{
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	fac[0] = 1;
	for (int i = 1; i < MAXN; i++) fac[i] = fac[i - 1] * i % mod;
//	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	int c, t;
	scanf("%lld%lld", &c, &t);
	while (t--)
	{
		int n, k; scanf("%lld%lld", &n, &k);
		for (int i = 1; i < n; i++)
		{
			int u, v; scanf("%lld%lld", &u, &v);
			to[u].push_back(v);
			to[v].push_back(u);
		}
		for (int i = 1; i <= k; i++)
		{
			int idx; scanf("%lld", &idx);
			vis[idx] = true;
		}
		int ret = 1;
		for (int i = 1; i <= n; i++) ret = ret * fac[to[i].size() - 1] % mod;
		printf("%lld\n", ret);
		for (int i = 1; i <= n; i++) to[i].clear();
	}
}

