#include<bits/stdc++.h>
#define LL long long

using namespace std;

const int mod = 1e9 + 7;

int inline read() {
	int x = 0; char ch = getchar();
	while (!isdigit(ch)) ch = getchar();
	while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return x;
}

int pow_mod(int a, int k) {
	int ret = 1;
	while (k) {
		if (k & 1) ret = (LL) ret * a % mod;
		a = (LL)a * a % mod;
		k >>= 1;
	}
	return ret;
}

int K, T;

const int maxn = 1e5 + 10;

int n, q;

vector<int> vec;

vector<int> G[maxn];
int oriu[maxn], oriv[maxn];

int iocnt[maxn];
int cnt[maxn];

int jie[maxn];

void init() {
	jie[0] = 1;
	for (int i = 1; i < maxn; i++) jie[i] = (LL)jie[i-1] * i % mod;
}

void clear() {
	for (int i = 1; i <= n; i++) G[i].clear();
	memset(iocnt, 0, sizeof(iocnt));
	memset(cnt, 0, sizeof(cnt));
	memset(oriu, 0, sizeof(oriu));
	memset(oriv, 0, sizeof(oriv));
	vec.clear();
}

void subtaskA() {
	cout << 1 << endl;
}

int cal(int n, int k) { // choose k from n
	if (n == 1) return 1;
	// n >= 2
	int sum = jie[n-1];
	int pick = jie[n-2];
	int res = ((LL)sum * k % mod - pick * ((LL)k * (k-1) / 2) % mod + mod) % mod;
	return res;
}

void subtaskB() {
	cout << cal(n-1, q) << endl;
}

void subtask1() {
	
}

int main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	
	K = read(), T = read();
	init();
	
	
	while (T--) {
		n = read(), q = read();
		clear();
		for (int i = 1; i <= n-1; i++) {
			int u = read(), v = read();
			G[u].push_back(v);
			G[v].push_back(u);
			oriu[i] = u, oriv[i] = v;
			iocnt[u]++, iocnt[v]++;
		}
		
		for (int x: vec) {
			cnt[oriu[x]]++, cnt[oriv[x]]++;
		}
		
		for (int i = 1; i <= q; i++) {
			int x;
			x = read();
			vec.push_back(x);
		}
		if (K == 18) {
			subtaskA();
			continue;
		}
		if (K >= 19 && K <= 21) {
			subtaskB();
			continue;
		}
		if (K <= 6) {
			subtask1();
			continue;
		}
	}
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}
