#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define LLL __int128
#define pii pair<int, int>
#define fi first
#define se second
#define mkp make_pair
#define sz(x) (int)x.size()
#define pb push_back
using namespace std;

int read() {
	int s = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
	while (ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
	return s * f;
}

template <typename T>
void chkmn(T &x, T y) { x = x < y ? x : y;}
template <typename T>
void chkmx(T &x, T y) { x = y < x ? x : y;}

const int mod = 1e9 + 7;

int qpow(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = 1ll * res * a % mod;
		a = 1ll * a * a % mod, b >>= 1;
	}
	return res;
}

auto fplus = [](int x, int y) {return x + y < mod ? x + y : x + y - mod;};
auto fminus = [](int x, int y) {return x >= y ? x - y : x + mod - y;};
auto Fplus = [](int &x, int y) {x = fplus(x, y);};
auto Fminus = [](int &x, int &y) {x = fminus(x, y);};

const int MAXN = 100005;

int c, t;

int n, k, u[MAXN], v[MAXN];
vector<int> e[MAXN];
int id[MAXN], d[MAXN], fac[MAXN];
int fa[MAXN], dep[MAXN];

void dfs(int x) {
	dep[x] = dep[fa[x]] + 1;
	for (int y : e[x])
		if (y != fa[x]) fa[y] = x, dfs(y);
}

int work() {
	n = read(), k = read();
	for (int i = 1; i <= n; i++) d[i] = 0, e[i].clear();
	bool lian = 1, juhua = 1;
	for (int i = 1; i < n; i++) {
		u[i] = read(), v[i] = read();
		d[u[i]]++, d[v[i]]++, e[u[i]].pb(v[i]), e[v[i]].pb(u[i]);
		lian &= u[i] == i && v[i] == i + 1, juhua &= u[i] == 1;
	}
	for (int i = 1; i <= k; i++) id[i] = read();
	fac[0] = 1;
	for (int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
	if (lian) return 1;
	if (juhua) {
		if (n == 2) return 1;
		int ans = 0;
		for (int i = 1; i <= k; i++)
			Fplus(ans, fminus(fac[n - 2], 1ll * (i - 1) * fac[n - 3] % mod));
		return ans;
	}
	int ans = 1;
	for (int i = 1; i <= n; i++)
		ans = 1ll * ans * fac[d[i] - 1] % mod;
	if (k == 1) return ans;
	int rt = u[id[1]];
	dfs(rt);
	int res = ans, p = dep[u[id[2]]] > dep[v[id[2]]] ? v[id[2]] : u[id[2]], ok = 0;
	while (p != rt) {
		if (p == v[id[1]]) ok = 1;
		if (d[p] > 2) res = 1ll * res * qpow(d[p] - 1, mod - 2) % mod;
		p = fa[p];
	}
//	cerr << ok << endl;
	if (!ok && d[p] > 2) res = 1ll * res * qpow(d[p] - 1, mod - 2) % mod;
	return fminus(fplus(ans, ans), res);
}

int main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	c = read(), t = read();
	while (t--) printf("%d\n", work());
	return 0;
}
