#include <bits/stdc++.h>
#define FileIO_(file) \
    freopen (file ".in", "r", stdin); \
    freopen (file ".out", "w", stdout);

using namespace std;

namespace Main {

namespace IO {

void read () {}

template<typename Tp, typename... Args>
void read (Tp &x, Args&... rest) {
    int c = getchar (); x = 0;
    while (!isdigit (c)) c = getchar ();
    do x = (x << 1) + (x << 3) + (c & 15);
    while (isdigit (c = getchar ()));
    read (rest...);
}

template<typename Tp>
void write (Tp x) {
    static int top, wr[50];
    do wr[++top] = x % 10; while (x /= 10);
    while (top) putchar (wr[top--] | 48);
}

} // namespace IO

using namespace IO;
using ll = long long;

const ll mod = 1e9 + 7;
const int maxn = 1e5 + 20;
int n, k, eid[maxn], deg[maxn];
ll ans, frac[maxn];

struct Edge {
    int u, v;
} e[maxn];

vector<int> g[maxn];

namespace K_eq_1 {

void solve () {
    ans = 1ll;
    fill (deg + 1, deg + n + 1, 0);
    for (int i = 1; i < n; ++i) {
        ++deg[e[i].u]; ++deg[e[i].v];
    }
    for (int i = 1; i <= n; ++i) {
        (ans *= frac[deg[i] - 1]) %= mod;
    }
    write (ans); putchar (10);
}

} // namespace K_eq_1

namespace K_eq_2 {

ll tot;

bool dfs (int u, int f, int b) {
    int flag = u == e[eid[2]].u || u == e[eid[2]].v;
    for (int v : g[u]) {
        if (v != f) {
            flag |= dfs (v, u, flag);
        }
    }
    if (b) flag = 0;
    (tot *= frac[deg[u] - flag - 1]) %= mod;
    return flag;
}

void solve () {
    ans = 1ll; tot = 1ll;
    for (int i = 1; i <= n; ++i) {
        deg[i] = 0; g[i].clear ();
    }
    for (int i = 1; i < n; ++i) {
        ++deg[e[i].u]; ++deg[e[i].v];
        g[e[i].u].emplace_back (e[i].v);
        g[e[i].v].emplace_back (e[i].u);
    }
    for (int i = 1; i <= n; ++i) {
        (ans *= frac[deg[i] - 1]) %= mod;
    }
    dfs (e[eid[1]].u, e[eid[1]].v, 0);
    dfs (e[eid[1]].v, e[eid[1]].u, 0);
    ans = (2 * ans - tot + mod) % mod;
    write (ans); putchar (10);
}

} // namespace K_eq_2

namespace SubA {

void solve () {
    puts ("1");
}

} // namespace SubA

namespace SubB {

void solve () {
    if (n == 2) puts ("1");
    else {
        ans = (k * frac[n - 2] - (ll) k * (k - 1) / 2 * frac[n - 3]);
        ans = (ans % mod + mod) % mod;
        write (ans); putchar (10);
    }
}

} // namespace SubB

// namespace Bf {

// const ll bx = 11451, by = 13331;
// ll px[2 * maxn], py[2 * maxn];
// unordered_set<array<ll, 2> > s;

// void init () {
//     px[0] = py[0] = 1ll;
//     for (int i = 1; i < 2 * maxn; ++i) {
//         px[i] = px[i - 1] * bx % mod;
//         py[i] = py[i - 1] * by % mod;
//     }
// }

// void dfs () {

// }

// void solve () {
//     init ();
//     for (int i = 1; i <= k; ++i) {

//     }
//     write (ans);
// }

// } // namespace Bf

void init () {
    frac[0] = 1ll;
    for (int i = 1; i < maxn; ++i) {
        frac[i] = frac[i - 1] * i % mod;
    }
}

void solve (const int &c) {
    read (n, k);
    for (int i = 1; i < n; ++i) {
        read (e[i].u, e[i].v);
    }
    for (int i = 1; i <= k; ++i) {
        read (eid[i]);
    }
    if (1 <= c && c <= 6) return K_eq_1::solve ();
    if (7 <= c && c <= 10) return K_eq_2::solve ();
    if (18 <= c && c <= 18) return SubA::solve ();
    if (19 <= c && c <= 21) return SubB::solve ();
    // return Bf::solve ();
}

int main () {
    init ();
    int c, t; read (c, t);
    while (t--) solve (c);
    return 0;
}

} // namespace Main

int main () {
    FileIO_("traverse");
    return Main::main ();
}