#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <queue>
#include <utility>
#include <random>
#define fi first
#define se second
using namespace std;
typedef long long LL;

template <typename Tp> inline void read(Tp& x) {
    char ch; bool op = 0; x = 0;
    do ch = getchar(), op |= ch == '-'; while (ch < '0' || ch > '9');
    do x = (x<<3)+(x<<1)+(ch&15), ch = getchar(); while (ch >= '0' && ch <= '9');
    if (op) x = -x;
}

template <typename Tp> inline void write(Tp x, char ed='\n') {
    static int arr[50]; int tp = 0;
    if (x < 0) putchar('-'), x = -x;
    do arr[++tp] = x % 10, x /= 10; while (x);
    for (; tp; --tp) putchar(arr[tp] | 48);
    putchar(ed);
}

const int mod = 1e9+7;
inline int fplus(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
inline int Fplus(int& x, int y) { return x = fplus(x, y); }
inline int fminus(int x, int y) { return x - y < 0 ? x - y + mod : x - y; }
inline int Fminus(int& x, int y) { return x = fminus(x, y); }

bool Mst;
const int MAXN = 1e5+5;

int n, k;
int head[MAXN], ver[MAXN<<1], nxt[MAXN<<1], tot;
int e[MAXN];
void add(int x, int y) {
    ver[++tot] = y, nxt[tot] = head[x], head[x] = tot;
}
int frac[MAXN];

int dfs(int x, int pa) {
//    fprintf(stderr, "%d\n", x);
    int deg = 0, res = 1;
    for (int i = head[x]; i; i = nxt[i]) {
        int y = ver[i];
        if (y == pa) continue;
        ++deg, res = 1ll * res * dfs(y, x) % mod;
    }
    res = 1ll * res * frac[deg] % mod;
    return res;
}

bool Med;


int main() {
    freopen("traverse.in", "r", stdin);
    freopen("traverse.out", "w", stdout);
    fprintf(stderr, "%.3lf\n", (&Mst - &Med) / 1048576.);
    int T, tid; read(tid), read(T);
    frac[0] = 1;
    for (int i = 1; i <= 1e5; ++i) frac[i] = 1ll * frac[i-1] * i % mod;
    while (T--) {
        read(n), read(k), tot = 1;
        memset(head, 0, sizeof(head));
        for (int i = 1; i < n; ++i) {
            int x, y; read(x), read(y); 
            add(x, y), add(y, x);
        }
        for (int i = 1; i <= k; ++i) {
            read(e[i]);
        }
        if (tid == 18) puts("1");
        else if (tid >= 19 && tid <= 21) {
            write((1ll * (n-1) * (n-2) - 1ll * (n-1-k) * (n-2-k)) / 2 % mod * frac[n-3] % mod);
        } else if (tid <= 6) {
            int x = ver[e[1]<<1], y = ver[e[1]<<1|1];
            write(1ll * dfs(x, y) * dfs(y, x) % mod);
        }
    }
    return 0;
}

