#include <bits/stdc++.h>
#define int long long
using namespace std;

const int mod = 1e9 + 7;

struct edge {
    int v, nxt, id;
}line[100010 * 2];
int cnt;
int head[100010];

void add(int u, int v, int id) {
    cnt++;
    line[cnt].v = v;
    line[cnt].id = id;
    line[cnt].nxt = head[u];
    head[u] = cnt;
}

struct lstore {
    int u, v, id;
}ls[100010];

int read() {
    int ret = 0, f = 1;
    char c;
    do{
        c = getchar();
        if(c == '-') {
            f = -1;
        }
    }while(!isdigit(c));
    do{
        ret *= 10;
        ret += c - '0';
        c = getchar();
    }while(isdigit(c));
    return ret * f;
}

int keys[100010];

int fc(int t) {
    int ret = 1;
    for(int i = 2; i <= t; ++i) {
        ret *= i;
        ret %= mod;
    }
    return ret;
}

int ans = 0;

map<int, bool> walked;
vector<vector<lstore>> dup;

int dfs(lstore l) {
    int lans = 0, rans = 0;
    for(int i = head[l.u]; i; i = line[i].nxt) {
        int v = line[i].v;
        int id = line[i].id;
        if(walked[id]) {
            continue;
        } 
        walked[id] = true;
        lans += dfs(lstore {
            l.u,
            v,0
        });
        ans %= mod;
        walked[id] = false;
    }
    for(int i = head[l.v]; i; i = line[i].nxt) {
        int v = line[i].v;
        int id = line[i].id;
        if(walked[id]) {
            continue;
        }
        walked[id] = true;
        rans += dfs(lstore {
            l.v,
            v,0
        });
        ans %= mod;
        walked[id] = false;
    }
    return max(max(lans, 1ll) * max(rans, 1ll), 1ll);
}

int fastpow(int a, int b) {
	if(b == 0) {
		return 1;
	}
	int tmp = fastpow(a, b / 2);
	tmp *= tmp;
	tmp %= mod;
	if(b % 2) {
		tmp *= a;
		tmp %= mod;
	}
	return tmp;
}

signed main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
    int c = read(), t = read();
    while(t--) {
        int n = read(), k = read();
        bool a_special = true;
        bool b_special = true;
        for(int i = 1; i <= n - 1; ++i) {
            int u = read(), v = read();
            add(u, v, i);
            add(v, u, i);
            if(v != u + 1) {
                a_special = false;
            }
            if(u != 1 || v != i + 1) {
                b_special = false;
            }
            ls[i] = lstore {
                u, v, i
            };
        }
        for(int i = 1; i <= k; ++i) {
            keys[i] = read();
        }
        if(a_special) {
            puts("1");
        } else if(n <= 5) {
            ans = 0;
            for(int i = 1; i <= k; ++i) {
                walked[ls[i].id] = true;
                ans += dfs(ls[i]);
                walked[ls[i].id] = false;
            }
            printf("%lld\n", ans);
        } else if(b_special) {
            int ans = fc(n - 1) * fastpow(n, mod - 2) % mod * k % mod;
            ans %= mod;
            printf("%lld\n", ans);
        }
    }
    return 0;
}