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

using ll = long long;
using ull = unsigned long long;
using ldb = long double;
using ui = unsigned int;

#define mp make_pair
#define eb emplace_back
#define fi first
#define se second

#ifdef _DEBUG
#define dbg(...) __VA_ARGS__
#else
#define dbg(...) void();
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int radint(int l, int r) {
  return uniform_int_distribution<>(l, r)(rng);
}

const int mod = 1e9 + 7;

ll qpow(ll a, ll b) {
  ll res = 1;
  for (; b; b >>= 1, a = a * a % mod)
    if (b & 1) res = res * a % mod;
  return res;
}

namespace Task1 {
  const int N = 1e5 + 5;
  struct Graph {
    int head[N], nxt[N * 2], to[N * 2], tot;
    bool dis[N * 2];
    void add(int u, int v) {
      nxt[++tot] = head[u];
      to[tot] = v;
      dis[tot] = false;
      head[u] = tot;
    }
    void clear(int n) {
      for (int i = 1; i <= n; ++i) head[i] = 0;
      tot = 1;
    }
  } G;
  ll fac[N], inv_fac[N];
  ll ncr(int x, int y) {
    if (x < y) return 0;
    return fac[x] * inv_fac[y] % mod * inv_fac[x - y] % mod;
  }
  ll f[N][2];
  bool leaf[N];
  void dfs(int x, int fa, bool fadis) {
    int cnt0 = 0, cnt1 = 0;
    for (int i = G.head[x]; i; i = G.nxt[i]) {
      if (G.to[i] == fa) continue;
      leaf[x] = false;
      if (G.dis[i]) ++cnt1;
      else ++cnt0;
      dfs(G.to[i], x, G.dis[i]);
    }
    if (fa) {
      for (int tx = 0; tx <= min(2, cnt0); ++tx) {
        for (int ty = 0; ty <= min(2, cnt1); ++ty) {
          if (!tx && !ty) continue;
          if (tx + ty > 2) continue;
          ll val = ncr(cnt0, tx) * ncr(cnt1, ty) % mod;
          for (int l = tx + ty + 1; l <= cnt0 + cnt1; ++l) {
            val *= (l - 1);
            val %= mod;
          }
          (f[x][!!(tx) || (fadis && tx + ty == 1)] += val) %= mod;
        }
      }
    } else {
      f[x][!!cnt1] = fac[cnt0 + cnt1 - 1];
    }
  }
  ll g[N][2];
  void calc(int x, int fa) {
    g[x][0] = f[x][0];
    g[x][1] = f[x][1];
    for (int i = G.head[x]; i; i = G.nxt[i]) {
      if (G.to[i] == fa) continue;
      if (leaf[G.to[i]]) continue;
      calc(G.to[i], x);
      g[x][1] = (g[x][1] * (g[G.to[i]][0] + g[G.to[i]][1]) % mod + g[x][0] * (g[G.to[i]][1]) % mod) % mod;
      (g[x][0] *= g[G.to[i]][0]) %= mod;
    }
  }
  void solve() {
    int n, k;
    cin >> n >> k;
    G.clear(n);
    for (int i = 1; i <= n; ++i) f[i][0] = f[i][1] = 0, leaf[i] = true;
    fac[0] = 1;
    for (int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i % mod;
    inv_fac[n] = qpow(fac[n], mod - 2);
    for (int i = n; i >= 1; --i) inv_fac[i - 1] = inv_fac[i] * i % mod;
    for (int i = 1; i < n; ++i) {
      int u, v;
      cin >> u >> v;
      G.add(u, v);
      G.add(v, u);
    }
    for (int i = 1; i <= k; ++i) {
      int x;
      cin >> x;
      G.dis[2 * x] = G.dis[2 * x + 1] = true;
    }
    dfs(1, 0, false);
    calc(1, 0);
    cout << g[1][1] << '\n';
  }
  void main() {
    int tt;
    cin >> tt;
    while (tt--) solve();
  }
}
namespace Task2 {
  void main() {
    int t;
    cin >> t;
    while (t--) {
      cout << "1\n";
    }
    return;
  }
}
namespace Task3 {
  void solve() {
    int n, k;
    cin >> n >> k;
    for (int i = 1; i < n; ++i) {
      int u, v;
      cin >> u >> v;
    }
    for (int i = 1; i <= k; ++i) {
      int x;
      cin >> x;
    }
    ll ans = k;
    for (int i = 1; i < n - 1; ++i)
      (ans *= i) %= mod;
    ll val = 1ll * k * (k - 1) / 2;
    for (int i = 1; i < n - 2; ++i)
      (val *= i) %= mod;
    ans = (ans + mod - val) % mod;
    cout << ans << '\n';
  }
  void main() {
    int t;
    cin >> t;
    while (t--) {
      solve();
    }
    return;
  }
}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  freopen("traverse.in", "r", stdin);
  freopen("traverse.out", "w", stdout);
  int cid;
  cin >> cid;
  if (cid == 18) {
    Task2::main();
    return 0;
  } else if (cid == 19) {
    Task3::main();
    return 0;
  }
  Task1::main();
  return 0;
}
