#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define Siz(a) ((int)(a.size()))
#define rz resize
#define MP make_pair
#define MT make_tuple
#define IT iterator
#define pb push_back
#define eb emplace_back
#define For(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define Rep(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)
#define CLR(a, v) memset(a, v, sizeof(a))
#define CPY(a, b) memcpy(a, b, sizeof(a))
#define y0 ztxaknoi
#define y1 ztxakioi
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uint = unsigned int;
using i128 = __int128_t;
using u128 = __uint128_t;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using vi = vector<int>;
template<typename T>
using V = vector<T>;
mt19937 rnd(time(0));
const int N = 1e5 + 7, MOD = 1e9 + 7;
int n, k, fac[N], ifac[N];
int qpow(int x, int p) {
int ans = 1;
while (p) {
if (p & 1) ans = 1ll * ans * x % MOD;
p >>= 1, x = 1ll * x * x % MOD;
}
return ans;
}
V<pii> G[N];
bool e[N];
int rt, f[N][2][2];
void add(int &x, int y) {
x += y;
if (x >= MOD) x -= MOD;
}
void sub(int &x, int y) {
x -= y;
if (x < 0) x += MOD;
}
void dfs(int u, int fa) {
if (G[u].size() <= 1) {
For(i, 0, 1) f[u][0][i] = 1;
return ;
}
for (auto [v, w] : G[u]) {
if (v == fa) continue;
dfs(v, u);
}
auto slv1 = [&] () -> void {
if (u == rt) return ;
array<array<int, 2>, 2> dp;
dp.fill(array<int, 2>{0});
dp[0][0] = 1;
for (auto [v, w] : G[u]) {
if (v == fa) continue;
array<array<int, 2>, 2> nw;
nw.fill(array<int, 2>{0});
For(i, 0, 1) {
if (e[w]) sub(nw[1][1], 1ll * dp[0][i] * (f[v][0][1] + f[v][1][1]) % MOD);
add(nw[1][1], 1ll * dp[0][i] * f[v][1][1] % MOD);
add(nw[1][i], 1ll * dp[0][i] * f[v][0][1] % MOD);
}
For(i, 0, 1) For(j, 0, 1) add(nw[i][j], 1ll * dp[i][j] * f[v][0][1] % MOD);
dp.swap(nw);
}
For(i, 0, 1) add(f[u][i][1], dp[1][i]);
};
auto slv2 = [&] () -> void {
int mul = 1ll * Siz(G[u]) * (Siz(G[u]) - 1) / 2 % MOD;
for (auto [v, w] : G[u]) {
if (v == fa) continue;
mul = 1ll * mul * f[v][0][0] % MOD;
}
add(f[u][0][0], mul);
mul = Siz(G[u]) - 1;
int sum = 0;
for (auto [v, w] : G[u]) {
if (v == fa) continue;
sum = 1ll * sum * f[v][0][1] % MOD;
if (e[w]) sub(sum, 1ll * mul * (f[v][1][1] + f[v][0][1]) % MOD);
add(sum, 1ll * mul * f[v][1][0] % MOD);
mul = 1ll * mul * f[v][0][1] % MOD;
}
add(f[u][1][0], sum);
array<int, 3> dp;
dp.fill(0);
dp[0] = 1;
for (auto [v, w] : G[u]) {
if (v == fa) continue;
Rep(i, 2, 0) {
dp[i] = 1ll * dp[i] * f[v][0][1] % MOD;
if (i) {
if (e[w]) sub(dp[i], 1ll * dp[i - 1] * (f[v][1][1] + f[v][0][1]) % MOD);
add(dp[i], 1ll * dp[i - 1] * f[v][1][1] % MOD);
}
}
}
add(f[u][1][0], dp[2]);
};
slv1(), slv2();
}
void Main() {
cin >> n >> k;
For(i, 1, n) For(x, 0, 1) For(y, 0, 1) f[i][x][y] = 0;
fac[0] = 1;
For(i, 1, n) fac[i] = 1ll * fac[i - 1] * i % MOD;
ifac[n] = qpow(fac[n], MOD - 2);
Rep(i, n, 1) ifac[i - 1] = 1ll * ifac[i] * i % MOD;
For(i, 1, n) G[i].clear();
For(i, 1, n - 1) {
int u, v; cin >> u >> v, G[u].eb(v, i), G[v].eb(u, i);
}
For(i, 1, n - 1) e[i] = 0;
For(i, 1, k) { int id; cin >> id, e[id] = 1; }
if (n == 2) return void(cout << "1\n");
rt = 0;
For(i, 1, n) if (G[i].size() >= 2) { rt = i; break; }
dfs(rt, 0);
int ans = f[rt][1][0];
if (ans) ans = MOD - ans;
For(i, 1, n) if (G[i].size() >= 2) ans = 1ll * ans * fac[G[i].size() - 2] % MOD;
cout << ans << '\n';
}
int main() {
freopen("traverse.in", "r", stdin) && freopen("traverse.out", "w", stdout);
ios::sync_with_stdio(0), cin.tie(0);
int c, t; cin >> c >> t;
while (t--) Main();
cerr << (double)(clock()) / CLOCKS_PER_SEC << '\n';
return 0;
}