#include<bits/stdc++.h>
#define int long long
#define mod 1000000007 
using namespace std;
int c, T, n, k;
vector<int> g[100005];
struct node{
	int u, v;
} s[100005];
int val[100005], jc[100005];
int d[100005], e[100005], f[100005], now;
void dfs(int u, int fa){
	if(d[u] == 1 && fa) f[u] = 1;
	int cnt = 0;
	for(auto v:g[u]) if(v != fa && d[v] == 1) ++cnt;
	for(auto v:g[u]){
		if(v == fa) continue;
		dfs(v, u);
		if(v == s[e[now]].u || v == s[e[now]].v) f[u] += f[v];
		else if(d[v] != 1) f[u] += val[d[u]-2-cnt]*(1+jc[cnt])%mod*f[v]%mod;
	}
	if(cnt && !f[u]) f[u] = jc[cnt];
	f[u] %= mod;
}
signed main(){
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	val[0] = 1, val[1] = 1; jc[0] = 1, jc[1] = 1;
	for(int i = 2; i <= 100000; i++) val[i] = (val[i-1]*i+1)%mod, jc[i] = jc[i-1]*i%mod;
	cin >> c >> T;
	while(T--){
		cin >> n >> k;
		for(int i = 1; i <= n; i++) g[i].clear(), d[i] = 0;
		for(int i = 1; i < n; i++){
			cin >> s[i].u >> s[i].v;
			g[s[i].u].push_back(s[i].v);
			g[s[i].v].push_back(s[i].u);
			d[s[i].u]++, d[s[i].v]++;
		} for(int i = 1; i <= k; i++) cin >> e[i];
		int res = 0;
		for(int i = 1; i <= k; i++){
			now = i;
			for(int j = 1; j <= n; j++) f[j] = 0;
			dfs(s[e[i]].u, 0);
			res += f[s[i].u];
		}
		cout << res%mod << endl;
	}
	return 0;
}

