#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int c, T;
int n, k;
int st;
int u[100005], v[100005], t[100005];
long long ans = 1;
long long fac[100005];
vector<pair<int, int>> e[100005];
void dfs(int k, int fath){
	int sum = 0;
	for (auto x : e[k]){
		if (x.first != fath && x.second != st){
			sum++;
		}
		if (x.first != fath){
			dfs(x.first, k);
		}
	}
	ans = (ans * fac[sum]) % mod;
}
int main()
{
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0); 
	fac[0] = 1;
	for (int i = 1; i <= 100000; i++){
		fac[i] = (fac[i - 1] * i) % mod;
	}
	cin >> c >> T;
	while (T--){
		cin >> n >> k;
		for (int i = 1; i <= n; i++){
			e[i].clear();
		}
		for (int i = 1; i < n; i++){
			cin >> u[i] >> v[i];
			e[u[i]].push_back({v[i], i});
			e[v[i]].push_back({u[i], i});
		}
		for (int i = 1; i <= k; i++){
			cin >> t[i];
		}
		if (k == 1){
			cerr << 123 << endl;
			ans = 1;
			st = t[1];
			dfs(u[st], u[st]);
			cout << ans << '\n';
		}
		else if (c == 18){
			cout << 1 << '\n';
		}
		else if (19 <= c && c <= 21){
			long long ans = 0;
			for (int i = 1; i <= k; i++){
				ans = (ans + fac[n - 2]) % mod;
				ans = (ans - (fac[n - 3] * (i - 1) % mod) + mod) % mod;
			}
			cout << ans << '\n';
		}
	}
	return 0;
}
/*
1 1
4 1
1 2
2 3
2 4
1
*/
