#include <iostream>
using namespace std;
const int N = 1e5 + 7;
const int O = 1e9 + 7;
typedef long long i64;

i64 fpow(i64 x, i64 k) {
	i64 r = 1;
	for(; k; k >>= 1, x = x * x %O)
		if(k & 1) r = r * x %O;
	return r;
}
#define inv(x) (fpow((x),O-2))

i64 frac[N], ifac[N];
void init() {
	frac[0] = 1;
	for(int i = 1; i < N; ++i)
		frac[i] = frac[i-1] * i %O;
	ifac[N-1] = inv(frac[N-1]);
	for(int i = N - 2; i >= 0; --i)
		ifac[i] = ifac[i + 1] * (i + 1) %O;
}

inline i64 C(int n, int m) {
	return frac[n] * ifac[m] %O * ifac[n - m] %O;
}

struct edge {
	int x, y;
	inline int get(int z) {
		return x ^ y ^ z;
	}
} e[N];

int n, k, d[N], flag[N];
int uf[N], df[N], fa[N];
basic_string<int> g[N];
i64 dp[N][2];
/*
0 -> down, by dot
1 -> down, by seg
*/

auto incr = [](auto& x, auto&& y) {x += y;
	if(x >= O) x-= O;
};
auto mult = [](auto& x, auto&& y) {x = x * y %O;};

inline void dfs(int u=1, int f=0) {
	fa[u] = f;
//	if(g[u].size() == 1) {
//		dp[u][0] = dp[u][1] = 1;
//	}
//	dp[u][1] = 1;
//	i64 vl = 1;
	for(int& i: g[u]) {
		int v = e[i].get(u);
		if(v == fa[u]) continue;
		dfs(v, u);
//		mult(dp[u][1], dp[v][0]);
//		mult(vl, dp[v][1]);
	}
//	for(int& i: g[u]) {
//		int v = e[i].get(u);
//		if(v == fa[u]) continue;
//		incr(dp[u][0], vl * inv(dp[v][1]) %O * dp[v][0] %O);
//	}
}

inline void preu(int u=1) {
	for(int& i: g[u]) {
		int v = e[i].get(u);
		if(v == fa[u]) continue;
		preu(v);
		uf[u] += uf[v] > 0 && !flag[v];
	}
}

inline void pred(int u=1) {
	for(int& i: g[u]) {
		int v = e[i].get(u);
		if(v == fa[u]) continue;
		if(df[u] || uf[u] >= 2 || (uf[u] == 1 && uf[v] == 0))
			df[v] = 1;
		pred(v);
	}
}

inline void solve() {
	cin >> n >> k;
	for(int i = 1; i <= n; ++i)
		g[i].clear(), d[i] = flag[i] = uf[i] = df[i] = 0;
	i64 ans = 1;
	for(int i = 1; i < n; ++i) {
		cin >> e[i].x >> e[i].y;
		++d[e[i].x], ++d[e[i].y];
		g[e[i].x] += i;
		g[e[i].y] += i;
	}
	dfs();
	for(int i, t = k; t--; ) {
		cin >> i;
		int x = e[i].x, y = e[i].y;
		if(x == fa[y]) swap(x, y);
		++flag[y];
	}
//	for(int i = 1; i <= n; ++i)
//		cout << uf[i] << ' ' << df[i] << "\n";
	preu(), pred();
	i64 ano = 1, cnt = 0;
	for(int i = 1; i <= n; ++i) {
		if(flag[i]) {
			i64 k = flag[i];
			if(d[i] == 1) ;
			else if(d[i] == 2) ano = 0;
			else mult(ano, frac[d[i] - k - 2]);
		}
		ans = ans * frac[d[i]-1] %O;
		if(d[i] > 1) ++cnt;
	}
//	for(int i = 1; i <= n; ++i)
//		cout << uf[i] << ' ' << df[i] << "\n";
//	i64 res = 0, rtp = 0, mul = 1;
//	for(int& i: g[1]) {
//		int v = e[i].get(1);
////		cout << v << "\n";
//		i64 vl = dp[v][0] * inv(dp[v][1]) %O;
//		mult(mul, dp[v][1]);
////		cout << vl << "\n";
//		incr(res, vl);
//		incr(rtp, vl * vl %O);
//	}
//	cout << dp[4][0] << ' ' << dp[4][1] << ' ' << dp[1][0] << "\n";
//	res = (res * res %O - rtp +O) * inv(2) %O;
//	cout << res << ' ' << ano << "\n";
	cout << ans << "\n";
}

int main() {
	init();
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int c, t; cin >> c >> t;
	for(; t--; ) solve();
}
/*
1 1
6 2
1 2
1 3
1 4
4 5
4 6
1 5
*/
