#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5;
const int mod = 1e9 + 7;
int fac[N + 5];
int c, t;
int n, k;
class graph {
	private:
	int idx;
	public:
	int head[N + 5];
	struct edge {
		int nxt, v;
	} e[(N << 1) + 5];
	void init(int n) {
		memset(head, 0, n + 1 << 2);
		idx = 0;
	}
	void add_dir(int u, int v) {
		e[++idx] = {head[u], v};
		head[u] = idx;
	}
	void add_udir(int u, int v) {
		add_dir(u, v), add_dir(v, u);
	}
} g;
int fa[N + 5], p[N + 5], cnt1[N + 5], cnt2[N + 5];
void dfs(int u = 1) {
	int cnt = 0;
	for (int i = g.head[u]; i; i = g.e[i].nxt) {
		int v = g.e[i].v;
		if (v == fa[u]) continue;
		fa[v] = u;
		p[i + 1 >> 1] = v;
		dfs(v);
		cnt++;
	}
	cnt1[u] = cnt;
	for (int i = g.head[u]; i; i = g.e[i].nxt) {
		int v = g.e[i].v;
		if (v != fa[u]) cnt2[v] = cnt;
	}
}
void solve() {
	scanf("%d%d", &n, &k);
	g.init(n);
	for (int _ = 1; _ < n; _++) {
		int u, v;
		scanf("%d%d", &u, &v);
		g.add_udir(u, v);
	}
	dfs();
	int ans = 0;
	for (int _ = 1; _ <= k; _++) {
		int x;
		scanf("%d", &x);
		x = p[x];
		if (c == 18) ans += 1 + (x != 2 && x != n);
		else {
			int tmp = 1;
			for (int u = 2; u <= n; u++)
				tmp = (LL)tmp * fac[cnt1[u]] % mod * fac[cnt2[u] - 1 + (u == x && fa[u] != 1)] % mod;
			ans = (ans + tmp) % mod;
		}
	}
	printf("%d\n", ans);
}
int main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	fac[0] = 1;
	for (int i = 1; i <= N; i++)
		fac[i] = (LL)fac[i - 1] * i % mod;
	scanf("%d%d", &c, &t);
	while (t--) solve();
	return 0;
}
