#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define R(i, x, y) for (int i = (x); i >= (y); i--)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout);

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
bool Mbe;

const int N = 1e5 + 5;
const int P = 1e9 + 7;
const int i2 = (P + 1) / 2;

int n, k, o;
int mx, d[N], x[N];
pi e[N];

vector<int> G[N];

void solve() {
	cin >> n >> k;
	F (i, 1, n - 1) {
		int u, v;
		cin >> u >> v;
		d[u]++, d[v]++;
		e[i] = mp(u, v);
	}
	F (i, 1, n) {
		mx = max(mx, d[i]);
	}
	F (i, 1, k) {
		int x; cin >> x;
		::x[i] = x;
	}
	if (o == 18) {
		cout << 1 << '\n';
	} else if (o == 19) {
		int fc = 1;
		n--;
		F (i, 1, n - 2) {
			fc = 1ll * fc * i % P;
		}
		cout << (P - 1ll * fc * k % P * (k - 1) % P * i2 % P + 1ll * fc * (n - 1) % P * k % P) % P << '\n';
	} else {
		if (n == 2) {
			cout << 1 << '\n';
		} else if (n == 3) {
			cout << 1 << '\n';
		} else if (n == 4) {
			if (mx == 2) {
				cout << 1 << '\n';
			} else {
				if (k == 1) {
					cout << 2 << '\n';
				} else {
					cout << 3 << '\n';
				}
			}
		} else {
			if (mx == 2) {
				cout << 1 << '\n';
			} else if (mx == 3) {
				int res = 0, ct = 0;
				F (i, 1, k) {
					if (d[e[x[i]].fi] == 1 && d[e[x[i]].se] == 2) {
						res = 1;
					} else if (d[e[x[i]].se] == 1 && d[e[x[i]].fi] == 2) {
						res = 1;
					} else if (d[e[x[i]].fi] == 3 && d[e[x[i]].se] == 2) {
						res = 1;
					} else if (d[e[x[i]].fi] == 2 && d[e[x[i]].se] == 3) {
						res = 1;
					} else {
						ct++;
					}
				}
				if (!ct) {
					cout << res * 2 << '\n';
				} else if (ct == 1) {
					cout << res + 2 << '\n';
				} else {
					cout << 3 << '\n';
				}
			} else {
				int fc = 1;
				n--;
				F (i, 1, n - 2) {
					fc = 1ll * fc * i % P;
				}
				cout << (P - 1ll * fc * k % P * (k - 1) % P * i2 % P + 1ll * fc * (n - 1) % P * k % P) % P << '\n';
			}
		}
	}
}

bool Med;
int main() {
	FIO("traverse");
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cerr << (&Mbe - &Med) / 1048576. << " MB\n";
	int T = 1;
	cin >> o >> T;
	while (T--) solve();
	cerr << 1. * clock() / CLOCKS_PER_SEC << " ms\n";
	return 0;
}
