#include <cstdio>
#define int long long
#define mod 1000000007
using namespace std;
void solve_special_A() {
    int T;
    scanf("%lld", &T);
    while (T--) {
        puts("1");
    }
}
void solve_special_B() {
    int T;
    scanf("%lld", &T);
    while (T--) {
        int n, k;
        scanf("%lld%lld", &n, &k);
        for (int i = 1; i < n; i++) {
            int u, v;
            scanf("%lld%lld", &u, &v);
        }
        for (int i = 1; i <= k; i++) {
            int e;
            scanf("%lld", &e);
        }
        int ans = 1, t = 1;
        for (int i = 1; i < n - 1; i++)
            ans = ans * i % mod;
        for (int i = 1; i < n - 2; i++)
            t = t * i % mod;
        printf("%lld\n", (ans * k % mod - k * (k - 1) % mod * 500000004 % mod * t % mod + mod) % mod);
    }
}
signed main() {
    freopen("traverse.in", "r", stdin);
    freopen("traverse.out", "w", stdout);
    int c;
    scanf("%lld", &c);
    if (c == 18)
        solve_special_A();
    if (c >= 19 && c <= 21)
        solve_special_B();
    return 0;
}