#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll rwt = 1;
const int mod = 1e9 + 7;
const int inv2 = 5e8 + 4;
const int N = 2e5 + 5;
struct Edge {
	int u, v, nxt;
} edge[N], edge2[N];
int Head[N], Head2[N], Pa[N], s1[N], Fac[N], Inv[N], De[N], tid, t, n, m, ans, E_cnt, E_cnt2;
bool vis[N], vis2[N], cc1;
void Solve();
int Find1(int x);
void add(int U, int V);
void add2(int U, int V);
int C(int x, int y);
int qpow(int x, int k);
void smd(int &x, int y);
void dmd(int &x, int y);
int rd();
int main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	Fac[0] = Fac[1] = Inv[0] = Inv[1] = 1;
	for (int i = 2; i <= N - 3; i++) {
		Fac[i] = rwt * Fac[i - 1] * i % mod;
	}
	Inv[N - 3] = qpow(Fac[N - 3], mod - 2);
	for (int i = N - 4; i > 1; i--) {
		Inv[i] = rwt * Inv[i + 1] * (i + 1) % mod;
	}
	scanf("%d%d", &tid, &t);
	while (t--) {
		Solve();
	}
	return 0;
}
void Solve() {
	int T1, T2, T3, T4;
	E_cnt = E_cnt2 = 1;
	memset(Head, 0, sizeof(Head));
	memset(Head2, 0, sizeof(Head2));
	memset(vis, 0, sizeof(vis));
	memset(vis2, 0, sizeof(vis2));
	memset(De, 0, sizeof(De));
	n = rd(), m = rd();
	for (int i = 1; i < n; i++) {
		T1 = rd(), T2 = rd();
		add(T1, T2);
		add(T2, T1);
	}
	for (int i = 1; i <= m; i++) {
		T1 = rd();
		vis[T1] = 1;
	}
	if (tid == 18) {
		printf("1\n");
		return;
	}
	if (19 <= tid && tid <= 21) {
		ans = rwt * m * Fac[n - 2] % mod;
		dmd(ans, rwt * m * (m - 1) % mod * inv2 % mod * Fac[n - 3] % mod);
		printf("%d\n", ans);
		return;
	}
	for (int ei = 1; ei < n; ei++) {
		T1 = edge[ei << 1].u, T2 = edge[ei << 1].v;
		T3 = T4 = 0;
		for (int i = Head[T1]; i; i = edge[i].nxt) {
			if ((i >> 1) == ei) {
				continue;
			}
			if ((i >> 1) < ei) {
				add2((i >> 1), ei);
			}
			T3++;
		}
		for (int i = Head[T2]; i; i = edge[i].nxt) {
			if ((i >> 1) == ei) {
				continue;
			}
			if ((i >> 1) < ei) {
				add2((i >> 1), ei);
			}
			T4++;
		}
		if (vis[ei] && T3 * T4 == 0) {
			vis2[ei] = 1;
			vis[ei] = 0;
		}
	}
	m = E_cnt2 - 1;
	for (int i = 0; i < (1 << m); i++) {
		T1 = 0;
		for (int x = 1; x < n; x++) {
			Pa[x] = x;
			De[x] = 0;
		}
		for (int j = 0; j < m; j++) {
			if ((i >> j) & 1) {
				T1++;
			}
		}
		if (T1 ^ (n - 2)) {
			continue;
		}
		cc1 = 0;
		for (int j = 0; j < m; j++) {
			if ((i >> j) & 1) {
				T1 = edge2[j + 2].u, T2 = edge2[j + 2].v;
				De[T1]++, De[T2]++;
				if (Find1(T1) == Find1(T2)) {
					cc1 = 1;
					break;
				}
				Pa[Find1(T1)] = Find1(T2);
			}
		}
		if (cc1) {
			continue;
		}
		//printf("	qzz0	%d\n", i);
		cc1 = 0;
		for (int j = 1; j < n; j++) {
			if (vis[j] || (vis2[j] && De[j] == 1)) {
				cc1 = 1;
				break;
			}
		}
		if (cc1) {
			//printf("	qzz1	%d\n", i);
			smd(ans, 1);
		}
	}
	printf("%d\n", ans);
}
int Find1(int x) {
	if (Pa[x] == x) {
		return x;
	}
	return Pa[x] = Find1(Pa[x]);
}
void add(int U, int V) {
	E_cnt++;
	edge[E_cnt].u = U;
	edge[E_cnt].v = V;
	edge[E_cnt].nxt = Head[U];
	Head[U] = E_cnt;
	return;
}
void add2(int U, int V) {
	E_cnt2++;
	edge2[E_cnt2].u = U;
	edge2[E_cnt2].v = V;
	edge2[E_cnt2].nxt = Head2[U];
	Head2[U] = E_cnt2;
	return;
}
int C(int x, int y) {
	if (x < y) {
		return 0;
	}
	return rwt * Fac[x] * Inv[y] % mod * Inv[x - y] % mod;
}
int qpow(int x, int k) {
	if (k < 1) {
		return 1;
	}
	int Ans = 1;
	for (int i = k; i; i >>= 1, x = rwt * x * x % mod) {
		if (i & 1) {
			Ans = rwt * Ans * x % mod;
		}
	}
	return Ans;
}
void smd(int &x, int y) {
	x = ((x + y < mod) ? x + y : x + y - mod);
	return;
}
void dmd(int &x, int y) {
	x = ((x < y) ? x - y + mod : x - y);
}
int rd() {
	int Ans = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		ch = getchar();
	}
	while ('0' <= ch && ch <= '9') {
		Ans = Ans * 10 + (ch - '0');
		ch = getchar();
	}
	return Ans;
}
