#include<bits/stdc++.h>
using namespace std;
vector<int> nodes[114514];
int c, T, n, k, l, r, alll[114514], allr[114514];
long long ans, mod = pow(10, 9) + 7;
long long dfs(int pos, int x, int sour){
	long long rtv = 0, cnt = max(1ll, (long long)nodes[pos].size() - 2);
	for(int i = 0; i < (int)nodes[pos].size(); i++){
		if(x != nodes[pos][i]){
			rtv += (dfs(nodes[pos][i], pos, 0) * cnt) % mod;
			rtv %= mod;
		}
	}
	if(!sour){
		return 1;
	}
	return rtv;
}
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 >> T;
	for(int z = 1; z <= T; z++){
		cin >> n >> k;
		for(int i = 1; i <= n; i++){
			nodes[i].clear();
		}
		for(int i = 1; i < n; i++){
			cin >> l >> r;
			alll[i] = l, allr[i] = r;
			nodes[l].push_back(r);
			nodes[r].push_back(l);
		}
		ans = 0;
		for(int j = 1; j <= k; j++){
			cin >> l;
			ans += dfs(alll[l], allr[l], 1) + dfs(allr[l], alll[l], 1);
		}
		cout << ans << '\n';
	}
}
