#include <algorithm>
#include <iostream>
#include <cstring>
#include <utility>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#define fi first
#define se second
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 100005;bool ve[N];vector<pii> to[N];
int t, n, q, fac[N], inv[N], rt, ft, fe, f[N][2][2], g[N], ans;
inline void add(int& x, int y){x += y;if (x >= mod) x -= mod;}
inline void mul(int& x, int y){x = 1ll * x * y % mod;}
void dp(int u, int fa, int e){
	if (to[u].size() == 1){f[u][0][ve[e]] = g[u] = 1;return;}
	int co = g[u] = fac[to[u].size() - 1], coo = fac[to[u].size() - 2];
	for (pii pi : to[u]) if (pi.fi != fa) dp(pi.fi, u, pi.se), mul(g[u], g[pi.fi]);
	int h[3][2] = {{1, 0}, {0, 0}, {0, 0}}, nh[3][2];
	for (pii pi : to[u]) if (pi.fi != fa){
		memset(nh, 0, sizeof(nh));
		for (int x = 0;x < 3;x ++)
		for (int y = 0;y < 2;y ++){
			add(nh[x][y], 1ll * h[x][y] * g[pi.fi] % mod);
			if (x < 2) add(nh[x + 1][y], 1ll * h[x][y] * f[pi.fi][0][0] % mod);
			if (x < 2) add(nh[x + 1][y | 1], 1ll * h[x][y] * f[pi.fi][0][1] % mod);
		}memcpy(h, nh, sizeof(h));
	}
	for (int y = 0;y < 2;y ++) add(f[u][1][y], 1ll * h[2][y] * coo % mod);
	memset(h, 0, sizeof(h)), h[0][0] = 1;
	for (pii pi : to[u]) if (pi.fi != fa){
		memset(nh, 0, sizeof(nh));
		for (int x = 0;x < 2;x ++)
		for (int y = 0;y < 2;y ++) add(nh[x][y], 1ll * h[x][y] * g[pi.fi] % mod);
		add(nh[1][0], 1ll * h[0][0] * f[pi.fi][1][0] % mod);
		add(nh[1][1], 1ll * h[0][0] * f[pi.fi][1][1] % mod);
		memcpy(h, nh, sizeof(h));
	}
	for (int y = 0;y < 2;y ++) add(f[u][1][y], 1ll * h[1][y] * co % mod);
	memset(h, 0, sizeof(h)), h[0][0] = 1;
	for (pii pi : to[u]) if (pi.fi != fa){
		memset(nh, 0, sizeof(nh));
		for (int x = 0;x < 2;x ++)
		for (int y = 0;y < 2;y ++) add(nh[x][y], 1ll * h[x][y] * g[pi.fi] % mod);
		add(nh[1][0], 1ll * h[0][0] * f[pi.fi][0][0] % mod);
		add(nh[1][1], 1ll * h[0][0] * f[pi.fi][0][1] % mod);
		memcpy(h, nh, sizeof(h));
	}
	for (int y = 0;y < 2;y ++) add(f[u][0][y | ve[e]], 1ll * h[1][y] * coo % mod);
}
int main(){
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> t, cin >> t, fac[0] = inv[1] = 1, n = N - 5;
	for (int i = 1;i <= n;i ++) mul(fac[i] = i, fac[i - 1]);
	for (int i = 2;i <= n;i ++) mul(inv[i] = inv[mod % i], mod - mod / i);
	while (t --){cin >> n >> q, rt = 0;
		for (int i = 1;i <= n;i ++) to[i].clear(), g[i] = f[i][0][0] = f[i][0][1] = f[i][1][0] = f[i][1][1] = 0;
		for (int i = 1, u, v;i < n;i ++) cin >> u >> v,
		ve[i] = 0, to[u].emplace_back(v, i), to[v].emplace_back(u, i);
		for (int i = 1;i <= n;i ++) if (to[i].size() == 1) ft = i, rt = to[i][0].fi, fe = to[i][0].se;
		if (!rt) exit(1);for (int e;q --;) cin >> e, ve[e] = 1;
		dp(rt, ft, fe), cout << (f[rt][0][1] + f[rt][1][1]) % mod << '\n';
	}
}
