#include<bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
using namespace std;
typedef long long ll;
const int N = 100005,mod = 1e9 + 7;
ll f[N],pw[N],F[N];
int c,n,m,u[N],v[N],e[N],sz[N];
int tot,head[N],ver[2*N],Next[2*N];
void add(int x,int y){
	tot++;
	ver[tot] = y;
	Next[tot] = head[x];
	head[x] = tot;
}
void init(){
	tot = 0;
	memset(head,0,sizeof(head));
}
/*ll C(int a,int b){
	return F[a] * inv[b] % mod * inv[a - b] % mod;
}*/
void dfs(int fa,int x){
	sz[x] = 1;
	f[x] = 1;int dg = 0,tg = 0;
	for(int i = head[x];i;i = Next[i]){
		int y = ver[i];
		if(y == fa)continue;
		dfs(x,y);
		sz[x] += sz[y];
//		if(sz[y] > 1)tg++;
		dg++,f[x] = f[x] * f[y] % mod;
	}
	f[x] = f[x] * F[dg] % mod * pw[tg] % mod;
}
void solve(){
	cin >> n >> m;
	init();
	for(int i = 1;i < n;i++){
		cin >> u[i] >> v[i];
		add(u[i],v[i]),add(v[i],u[i]);
	}
	for(int i = 1;i <= m;i++)
		cin >> e[i];
	if(c == 18)return cout << "1\n",void(); 
	else if(c >= 19 && c <= 21){
		ll res = m * F[n - 2] % mod;
		if(m >= 2)res = ((res - 1ll * m * (m - 1) / 2 % mod * F[n - 3]) % mod + mod) % mod;
		return cout << res << '\n',void();
	}
	ll ans = 0;
	for(int i = 1;i <= m;i++){
		dfs(u[e[i]],v[e[i]]);
		dfs(v[e[i]],u[e[i]]);
		ans += f[u[e[i]]] * f[v[e[i]]] % mod;
	}
	cout << ans % mod << '\n';
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cin.tie(0);
	ios::sync_with_stdio(0);
	int T;cin >> c >> T;
	pw[0] = F[0] = 1;
	for(int i = 1;i < N;i++)
		pw[i] = pw[i - 1] * 2 % mod,F[i] = F[i - 1] * i % mod;
	while(T--)solve();
	return 0;
}

