#include using namespace std; namespace FastRead{ inline char gc() { static char buf[1 << 20 | 5], *s = buf, *t = buf; return s == t && (t = (s = buf) + fread(buf, 1, 1 << 20, stdin), s == t) ? EOF : *s ++ ; } template inline void Read(T &x) { x = 0; char ch = gc(); while(ch < '0' || ch > '9') ch = gc(); while('0' <= ch && ch <= '9') x = x * 10 + (ch ^ 48), ch = gc(); } } using FastRead::Read; typedef long long LL; const int N = 1e5 + 5, P = 1e9 + 7; int n, k; int la[N], ne[N * 2], en[N * 2], idx; int st[N], mark[N]; int deg[N]; LL fact[N], invf[N], inv[N]; LL f[N], ans; inline LL ksm(LL a, LL n) { LL res = 1; while(n) { if(n & 1) res = res * a % P; a = a * a % P; n >>= 1; } return res; } inline void Init(int n) { fact[0] = 1; for(int i = 1; i <= n; i ++ ) fact[i] = fact[i - 1] * i % P; invf[n] = ksm(fact[n], P - 2); for(int i = n; i >= 1; i -- ) invf[i - 1] = invf[i] * i % P; for(int i = 1; i <= n; i ++ ) inv[i] = invf[i] * fact[i - 1] % P; } inline void Add(int a, int b) { ne[ ++ idx] = la[a]; la[a] = idx; en[idx] = b; } inline void DP(int u, int fa) { for(int i = la[u]; i; i = ne[i]) { int v = en[i]; if(v != fa) { mark[v] = st[i >> 1]; DP(v, u); ans = (ans + (P - f[u]) * f[v]) % P; f[u] = (f[u] + f[v] * inv[deg[u] - 1]) % P; } } if(mark[u]) { ans = (ans + f[u]) % P; f[u] = P - 1; } } int main() { freopen("traverse.in", "r", stdin); freopen("traverse.out", "w", stdout); Init(N - 1); int T; Read(T), Read(T); while(T -- ) { Read(n), Read(k); idx = 1, ans = 0; for(int i = 1; i <= n; i ++ ) la[i] = st[i] = mark[i] = deg[i] = f[i] = 0; for(int i = 1; i < n; i ++ ) { int a, b; Read(a), Read(b); Add(a, b), Add(b, a); deg[a] ++ , deg[b] ++ ; } for(int i = 1; i <= k; i ++ ) { int x; Read(x); st[x] = 1; } ans = k; DP(1, 0); for(int i = 1; i <= n; i ++ ) ans = ans * fact[deg[i] - 1] % P; printf("%lld\n", ans); } return 0; }