#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
const int N = 1e5 + 10, mod = 1e9 + 7;
int c, T, n, k, e[N], ans;
struct EDGE {
    int u, v, w;
} edge[N];
bool vis[N];
int qpow(int x, int y) {
    if (y < 0)
        return 1;
    int ret = 1;
    for (; y; y >>= 1, x = x * x % mod)
        if (y & 1)
            ret = ret * x % mod;
    return ret;
}
void dfs(int st, int id, int &step) {
    if (step >= n - 1) {
        ans++;
        return;
    }
    for (int i = 1; i < n; i++) {
        if (step == n - 2 and i <= st)
            continue;
        if (vis[i])
            continue;
        if (edge[id].u != edge[i].u and edge[id].v != edge[i].v and edge[id].u != edge[i].v and edge[id].v != edge[i].u)
            continue;
        vis[i] = true;
        int tmp = step + 1;
        dfs(st, i, tmp);
        step = tmp;
        vis[i] = false;
    }
}
void solve() {
    cin >> n >> k;
    for (int i = 1, u, v; i < n; i++) {
        cin >> u >> v;
        edge[i] = {u, v};
    }
    for (int i = 1; i <= k; i++)
        cin >> e[i];
    if (c == 18) {
        cout << "1\n";
        return;
    }
    if (19 <= c and c <= 21) {
        int tmp = 1, ans = 0;
        for (int i = 1; i <= n - 2; i++)
            tmp = tmp * i % mod;
        for (int i = 1; i <= k; i++)
            ans = (ans + tmp - (i - 1) * tmp % mod * qpow(n - 2, mod - 2) % mod + mod) % mod;
        cout << ans << "\n";
        return;
    }
    ans = 0;
    for (int i = 1; i <= k; i++) {
        vis[e[i]] = true;
        int tmp = 1;
        dfs(e[i], e[i], tmp);
        vis[e[i]] = false;
    }
    cout << ans << "\n";
}
signed main() {
    freopen("traverse.in", "r", stdin);
    freopen("traverse.out", "w", stdout);
    IOS;
    cin >> c >> T;
    while (T--)
        solve();
    return 0;
}
/*
1
7 1 2
4 1
*/