#include <bits/stdc++.h>
using namespace std;

const int MXN = 100005;
const int MXE = MXN * 2;
const int DVS = 1e9 + 7;
int T, N, K, head[MXN], to[MXE], nxt[MXE], cnt[MXN], deg[MXN], ans;
bool mark[MXE];

int read() {
  int x(0), c(getchar());
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + (c - '0'), c = getchar();
  return x;
}

void dfs1(int p, int le) {
  cnt[p] = 0;
  for (int i(head[p]); ~i; i = nxt[i]) {
    if ((i ^ le) == 1) continue;
    dfs1(to[i], i);
    cnt[p] += (mark[i] || cnt[to[i]] > 0);
  }
}
void dfs2(int p, int le) {
  if (deg[p] >= 2) {
    int fac(1);
    for (int i(1); i <= deg[p] - 2; ++i) fac = fac * 1LL * i % DVS;
    int ths(fac * 1LL * (cnt[p] * 1LL * (deg[p] - 1) % DVS + DVS -
                         cnt[p] * 1LL * (cnt[p] - 1) / 2 % DVS) % DVS);
    ans = ans * 1LL * ths % DVS;
  }
  for (int i(head[p]); ~i; i = nxt[i]) {
    if ((i ^ le) == 1) continue;
    int q(to[i]);
    cnt[p] -= (mark[i] || cnt[q] > 0);
    cnt[q] += (mark[i] || cnt[p] > 0);
    dfs2(q, i);
    cnt[q] -= (mark[i] || cnt[p] > 0);
    cnt[p] += (mark[i] || cnt[q] > 0);
  }
}

int main() {
  freopen("traverse.in", "r", stdin);
  freopen("traverse.out", "w", stdout);
  for (read(), T = read(); T--;) {
    N = read(), K = read();
    for (int i(0); i != N; ++i) head[i] = -1, deg[i] = 0;
    for (int i(0), x(0), y(0); i != N - 1; ++i) {
      x = read() - 1, y = read() - 1;
      to[i << 1] = y, nxt[i << 1] = head[x], head[x] = i << 1;
      to[i << 1 | 1] = x, nxt[i << 1 | 1] = head[y], head[y] = i << 1 | 1;
      mark[i << 1] = mark[i << 1 | 1] = false;
      ++deg[x], ++deg[y];
    }
    for (int x(0); K--;)
      x = read() - 1, mark[x << 1] = mark[x << 1 | 1] = true;
    dfs1(0, -1);
    ans = 1;
    dfs2(0, -1);
    printf("%d\n", ans);
  }
  return 0;
}
