#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 3e5 + 5, p = 1e9 + 7;
inline int read(){
int x = 0;
char c = getchar();
while(!isdigit(c)) c = getchar();
while(isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return x;
}
int us[maxn], vs[maxn];
int head[maxn], nxt[maxn << 1], to[maxn << 1], cnt = 0;
int ks[maxn], tag[maxn << 1], ex[maxn], col[maxn];
ll k1[maxn], f[maxn][2];
ll fac[maxn], infa[maxn];
void match(int u, int v, int t){
nxt[++ cnt] = head[u], to[cnt] = v, tag[cnt] = t, head[u] = cnt;
}
void k1_dfs(int x, int f){
int s = 0;
k1[x] = 1;
for(int i = head[x]; i; i = nxt[i]){
int j = to[i];
if(j == f) continue;
k1_dfs(j, x);
k1[x] = k1[x] * k1[j] % p;
s ++;
}
k1[x] = k1[x] * fac[s] % p;
}
ll qpow(ll a, ll x){
ll res = 1;
while(x){
if(x & 1) res = res * a % p;
a = a * a % p;
x >>= 1;
}
return res;
}
void dfs(int x, int f){
ex[x] = 0;
for(int i = head[x]; i; i = nxt[i]){
int j = to[i];
if(j == f) continue;
dfs(j, x);
ex[x] |= ex[j] | tag[i];
}
}
ll pre[maxn], suf[maxn], val[maxn], pre_[maxn];
void calc(int x, int fa){
int s = 0;
for(int i = head[x]; i; i = nxt[i]){
int j = to[i];
if(j == fa) continue;
calc(j, x);
s ++;
pre[s] = suf[s] = f[j][0];
}
pre[0] = suf[s + 1] = 1;
for(int i = 1; i <= s; i ++) pre[i] = pre[i - 1] * pre[i] % p;
for(int i = s; i >= 1; i --) suf[i] = suf[i + 1] * suf[i] % p;
s ++;
f[x][0] = fac[s - 1], f[x][1] = 0;
ll d0 = 1;
int ss = s;
if(!fa) ss --;
s = 0;
ll R = 0;
for(int i = head[x]; i; i = nxt[i]){
int j = to[i];
if(j == fa) continue;
s ++;
if(fa) f[x][0] = f[x][0] * f[j][0] % p, d0 = d0 * f[j][0] % p;
if(ex[j]){
f[x][1] = (f[x][1] + f[j][1] * fac[ss - 1] % p * pre[s - 1] % p * suf[s + 1] % p) % p;
}
if(tag[i]){
if(ss > 1) f[x][1] = (f[x][1] + f[j][0] * (fac[ss - 1] + p - R * fac[ss - 2] % p) % p * pre[s - 1] % p * suf[s + 1] % p) % p;
else f[x][1] = (f[x][1] + f[j][0]) % p;
R ++;
}
}
s ++;
for(int i = head[x]; i; i = nxt[i]){
int j = to[i];
if(j == fa) continue;
if(fa && tag[i]) f[x][0] = (f[x][0] + p - d0 * fac[s - 2] % p) % p;
}
}
int main(){
freopen("traverse.in", "r", stdin);
freopen("traverse.out", "w", stdout);
fac[0] = 1;
for(int i = 1; i <= 1e5; i ++) fac[i] = fac[i - 1] * i % p;
infa[(int)1e5] = qpow(fac[(int)1e5], p - 2);
for(int i = 1e5 - 1; i >= 1; i --) infa[i] = infa[i + 1] * (i + 1) % p;
int c = read(), T = read();
while(T --){
int n = read(), k = read();
for(int i = 1; i < n; i ++) us[i] = read(), vs[i] = read();
for(int i = 1; i <= k; i ++){
ks[i] = read();
col[ks[i]] = 1;
}
for(int i = 1; i < n; i ++) match(us[i], vs[i], col[i]), match(vs[i], us[i], col[i]);
if(k == 1){
k1_dfs(us[ks[1]], vs[ks[1]]), k1_dfs(vs[ks[1]], us[ks[1]]);
printf("%lld\n", k1[us[ks[1]]] * k1[vs[ks[1]]] % p);
for(int i = 1; i <= n; i ++) head[i] = 0;
while(cnt) nxt[cnt] = to[cnt] = tag[cnt] = 0, cnt --;
continue;
}else if(c == 18){
printf("1\n");
for(int i = 1; i <= n; i ++) head[i] = 0;
while(cnt) nxt[cnt] = to[cnt] = tag[cnt] = 0, cnt --;
continue;
}else if(c >= 19 && c <= 21){
if(n == 2) printf("1\n");
else{
ll ans = (fac[n - 2] * k % p + p - fac[n - 3] * ((1ll * k * (k - 1) / 2) % p) % p) % p;
printf("%lld\n", ans);
}
for(int i = 1; i <= n; i ++) head[i] = 0;
while(cnt) nxt[cnt] = to[cnt] = tag[cnt] = 0, cnt --;
continue;
}
dfs(1, 0);
calc(1, 0);
printf("%lld\n", f[1][1]);
for(int i = 1; i <= n; i ++) head[i] = col[i] = 0;
while(cnt) nxt[cnt] = to[cnt] = tag[cnt] = 0, cnt --;
}
return 0;
}