#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
const int mod = 1e9 + 7;
int c, T;
int n, k;
long long ans = 1;
struct edge{
	int u, v;
}e[maxn];
bool is[maxn];
vector<int> G[maxn];
long long dfs(int u, int fa) {
	long long sum = 0;
	is[u] = 1;
	bool flag = 1;
	for(int i = 0; i < G[e[u].u].size(); i++) {
		int v = G[e[u].u][i];
		if(is[v] || v == u || v == fa) continue;
		flag = 0;
		sum = (sum + dfs(v, u)) % mod;
	}
	for(int i = 0; i < G[e[u].v].size(); i++) {
		int v = G[e[u].v][i];
		if(is[v] || v == u || v == fa) continue;
		flag = 0;
		sum = (sum + dfs(v, u)) % mod;
	}
	is[u] = 0;
	if(flag) return 1;
	return sum % mod;
}
int main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	scanf("%d%d", &c, &T);
	while(T--) {
		scanf("%d%d", &n, &k);
		for(int i = 1; i <= n; i++) G[i].clear();
		for(int i = 1; i < n; i++) {
			int u, v;
			scanf("%d%d", &u, &v);
			e[i] = {u, v};
			G[u].push_back(i);
			G[v].push_back(i);
		}
		ans = 0;
		for(int i = 1; i <= k; i++) {
			int s;
			scanf("%d", &s);
			ans = (dfs(s, 0) + ans) % mod;
		}
		printf("%lld\n", ans % mod);
	}
	return 0;
}
