#include <bits/stdc++.h>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 100010, p = 1e9 + 7;
int c, ttt, n, k, rt[N], cnt[N];
vector<pii> g[N];
vector<int> e[N];
bool vis[N];
queue<int> q;
bool bfs(int s) {
	q.push(s), vis[s] = 1;
	for (int u; !q.empty(); ) {
		u = q.front(); q.pop();
		for (int v : e[u]) if (!vis[v]) {
			q.push(v), cnt[u]++, vis[v] = 1;
		}
	}
}
void solve() {
	for (int i = 1; i <= n; i++) g[i].clear(), e[i].clear();
	cin >> n >> k;
	for (int i = 1, u, v; i < n; i++) {
		cin >> u >> v;
		g[u].push_back({v, i}), g[v].push_back({u, i});
	}
	for (int i = 1; i <= k; i++) cin >> rt[i];
	if (c == 18) {
		cout << "1\n";
		return ;
	} 
	for (int u = 1; u <= n; u++) {
		for (pii t : g[u]) {
			int v = t.fi, id = t.se;
			for (pii t2 : g[v]) {
				int w = t2.fi, id2 = t2.se;
				if (w == u) continue;
				e[id].push_back(id2);
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= k; i++) {
		int res = 1;
		for (int j = 1; j < n; j++) vis[j] = cnt[j] = 0;
		bfs(rt[i]);
		for (int j = 1; j < n; j++) {
			if (cnt[j]) res = 1ll * res * cnt[j] % p;
		}
		ans = (ans + res) % p;
	}
	cout << ans << '\n';
}
int main() {
	freopen("traverse.in", "r", stdin); freopen("traverse.out", "w", stdout);
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> c >> ttt;
	while (ttt--) solve();
} 
