#include <bits/stdc++.h>
using namespace std;

using ll = long long;

constexpr int N = 1e5 + 5;
constexpr ll MOD = 1e9 + 7;

int cid, t, n, k;
array<int, N> eu, ev;
ll ans;

void dfs(int S, int e)
{
	if (S == (1 << (n - 1)) - 1)
	{
		ans++;
		return;
	}
	int nu = eu[e], nv = ev[e];
	for (int i = 0; i < n; i++)
	{
		int u = eu[i], v = ev[i];
		if (!((S >> i) & 1))
		{
			if (nu == u || nu == v || nv == u || nv == v) dfs(S | (1 << i), i);
		}
	}
}

int main()
{
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> cid >> t;
	while (t--)
	{
		cin >> n >> k;
		for (int i = 0; i < n - 1; i++)
		{
			cin >> eu[i] >> ev[i];
		}
		int x;
		if (k == 1)
		{
			cin >> x;
			x--;
		}
		else
		{
			for (int j = 1; j <= k; j++)
			{
				int nn;
				cin >> nn;
			}
		}
		if (n > 5)
		{
			ans = 1ll;
			for (int i = 1; i <= n - 2; i++) ans = ans * i % MOD;
			cout << ans << "\n";
			continue;
		}
 		ans = 0;
		dfs(1 << x, x);
		cout << ans % MOD << "\n";
	}
	return 0;
}
