#include using namespace std; int read() { int x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') f = -f; c = getchar();} while (c >= '0' && c <= '9') {x = x * 10 + (c ^ 48); c = getchar();} return x * f; } int quickpow(int a, int b, int mod) { int res = 1; for (; b; b >>= 1, a = 1LL * a * a % mod) if (b & 1) res = 1LL * res * a % mod; return res; } typedef pair pii; const int N = 1e5 + 5, mod = 1e9 + 7; int td, n, K; vector e[N]; int fac[N], Inv[N], f[N][2][2], gg[N]; struct Edge { int u, v, op; } E[N]; void dfs(int x, int dad) { int g[3] = {}, h[3], G[2] = {}, H[2]; int W = 0; g[0] = G[0] = 1; gg[x] = fac[e[x].size() - 1]; for (auto p : e[x]) { int y = p.first, w = p.second; if (y == dad) {W = w; continue;} dfs(y, x); h[0] = h[1] = h[2] = 0; for (int i = 0; i < 3; i++) for (int j = 0; j < 2 && i + j < 3; j++) { if (!j) h[i + j] = (h[i + j] + 1LL * g[i] * f[y][j][0]) % mod; else h[i + j] = (h[i + j] + 1LL * g[i] * (f[y][j][0] + f[y][j][1])) % mod; } for (int i = 0; i < 3; i++) g[i] = h[i]; H[0] = H[1] = 0; for (int i = 0; i < 2; i++) for (int j = 0; i + j < 2; j++) H[i + j] = (H[i + j] + 1LL * G[i] * f[y][0][j]) % mod; for (int i = 0; i < 2; i++) G[i] = H[i]; f[x][0][1] = 1LL * f[x][0][1] * gg[y] % mod; f[x][0][1] = (f[x][0][1] + 1LL * f[y][1][1] * gg[x]) % mod; gg[x] = 1LL * gg[x] * gg[y] % mod; } f[x][0][0] = 1LL * g[0] * fac[e[x].size() - 1] % mod; if (e[x].size() > 1) { if (W) f[x][1][1] = (mod - 1LL * g[1] * fac[e[x].size() - 2] % mod) % mod; f[x][1][0] = 1LL * g[1] * fac[e[x].size() - 2] % mod; } if (W) f[x][1][1] = (f[x][1][1] - 1LL * g[0] * fac[e[x].size() - 1] % mod + mod) % mod; f[x][0][1] = (f[x][0][1] + 1LL * G[1] * fac[e[x].size() - 1]) % mod; if (e[x].size() > 1) f[x][0][1] = (f[x][0][1] + 1LL * g[2] * fac[e[x].size() - 2]) % mod; } void Solve() { n = read(); K = read(); fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = 1LL * fac[i - 1] * i % mod; Inv[n] = quickpow(fac[n], mod - 2, mod); for (int i = n - 1; ~i; i--) Inv[i] = 1LL * Inv[i + 1] * (i + 1) % mod; for (int i = 1; i <= n; i++) e[i].clear(), E[i].op = 0; memset(f, 0, sizeof(f)); for (int i = 1; i < n; i++) { E[i].u = read(); E[i].v = read(); } for (int i = 1; i <= K; i++) { int x = read(); E[x].op = 1; } for (int i = 1; i < n; i++) { e[E[i].u].push_back(make_pair(E[i].v, E[i].op)); e[E[i].v].push_back(make_pair(E[i].u, E[i].op)); } dfs(1, 0); printf("%d\n", (mod - f[1][0][1]) % mod); } int main() { freopen("traverse.in", "r", stdin); freopen("traverse.out", "w", stdout); td = read(); int _ = read(); while (_--) Solve(); return 0; }