#include <bits/stdc++.h>

using namespace std;
using str = string;

struct D {
  int r;
  int c0, c1;
};

const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inv2 = (mod + 1) / 2;
int fact[N], ifact[N];
int power(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1) res = 1ll * res * x % mod;
    x = 1ll * x * x % mod, y >>= 1;
  }
  return res;
}

int main() {
  freopen("traverse.in", "r", stdin);
  freopen("traverse.out", "w", stdout);
  ios::sync_with_stdio(false);
  cin.tie(0);
  fact[0] = 1;
  for (int i = 1; i < N; i++) fact[i] = 1ll * fact[i - 1] * i % mod;
  ifact[N - 1] = power(fact[N - 1], mod - 2);
  for (int i = N - 1; i >= 1; i--) ifact[i - 1] = 1ll * ifact[i] * i % mod;
  int c, T;
  cin >> c >> T;
  while (T--) {
    int n, k;
    cin >> n >> k;
    vector<pair<int, int>> e;
    vector<vector<int>> g(n);
    for (int i = 1; i < n; i++) {
      int u, v;
      cin >> u >> v;
      --u, --v;
      g[u].emplace_back(e.size());
      g[v].emplace_back(e.size());
      e.emplace_back(u, v);
    }
    vector<set<int>> vis(n);
    auto dfs = [&](auto &&dfs, int eid, int from) -> void {
      // cerr << eid << ' ' << from << '\n';
      int u = e[eid].first, v = e[eid].second;
      if (u != from && !vis[u].count(eid)) {
        vis[u].insert(eid);
        for (auto ne : g[u]) {
          if (ne != eid) {
            int nv = e[ne].first ^ e[ne].second ^ u;
            dfs(dfs, ne, u);
          }
        }
      }
      if (v != from && !vis[v].count(eid)) {
        vis[v].insert(eid);
        for (auto ne : g[v]) {
          if (ne != eid) {
            int nv = e[ne].first ^ e[ne].second ^ v;
            dfs(dfs, ne, v);
          }
        }
      }
    };
    for (int i = 0; i < k; i++) {
      int x;
      cin >> x;
      --x;
      dfs(dfs, x, -1);
    }
    // for (int i = 0; i < n; i++) {
    //   for (auto j : vis[i]) cout << j << ' ';
    //   cout << endl;
    // }
    int ans = 1;
    auto calc = [&](int n, int k) -> int {
      // cerr << n << ' ' << k << '\n';
      if (n == 1) return 1;
      if (n - 2 < k) return 1ll * fact[n] * inv2 % mod;
      int remove = 1ll * fact[n - 2] * ifact[n - 2 - k] % mod * fact[n - k] %
                   mod * inv2 % mod;
      return ((1ll * fact[n] * inv2 - remove) % mod + mod) % mod;
    };
    for (int i = 0; i < n; i++) {
      ans = 1ll * ans * calc(g[i].size(), vis[i].size()) % mod;
    }
    cout << ans << '\n';
  }
}
