#include<bits/stdc++.h>
using namespace std;
#define debug 0
const int M = 1e9 + 7;
int c, T;
int n, k;
vector<int>G[100003];
int u[100003], v[100003], e[100003];
int dp[100003];
int fact[200003] = {1};
int qpow(int a, int b){
	int res = 1;
	while (b > 0){
		if (b & 1) res = 1ll * res * a % M;
		a = 1ll * a * a % M;
		b >>= 1;
	}
	return res;
}
void dfs(int v, int fa){
	int s = 0;
	dp[v] = 1;
	for (int to : G[v])
		if (to ^ fa){
			++s;
			dfs(to, v);
			dp[v] = 1ll * dp[v] * dp[to] % M;
		}
	dp[v] = 1ll * dp[v] * fact[s] % M;
}
int main(){
	#if debug
		freopen("traverse10.in", "r", stdin);
		freopen("traverse10.out", "w", stdout);
	#else
		freopen("traverse.in", "r", stdin);
		freopen("traverse.out", "w", stdout);
	#endif
	for (int i = 1;i <= 2e5;++i)
		fact[i] = 1ll * fact[i - 1] * i % M;
	scanf ("%d%d", &c, &T);
	while (T--){
		scanf ("%d%d", &n, &k);
		for (int i = 1;i < n;++i){
			scanf ("%d%d", u + i, v + i);
			G[u[i]].push_back(v[i]), G[v[i]].push_back(u[i]);
		}
		for (int i = 1;i <= k;++i){
			scanf ("%d", e + i);
		}
		if (c <= 6){
			int tmp1, tmp2;
			dfs(u[e[1]], v[e[1]]);
			tmp1 = dp[u[e[1]]];
			dfs(v[e[1]], u[e[1]]);
			tmp2 = dp[v[e[1]]];
			printf ("%lld\n", 1ll * tmp1 * tmp2 % M);
		}
		else if (c == 18) printf ("1\n");
		else if (19 <= c && c <= 21){
			if (n <= 3) printf ("1\n");
			else printf ("%lld\n",
			(1ll * k * fact[n - 2] % M +
			M - (1ll * k * (k - 1) / 2) % M * fact[n - 3] % M) % M);
		}
	}
	return 0;
} 
