#include<bits/stdc++.h>
using namespace std;

using ll = long long;

const int N = 1e5 + 5;
const ll mod = 1e9 + 7;

int c,T,n,m,P[N];
ll dp[N],dp2[N],f[N],inv[N],g[N],ans[N];
vector<pair<int,int>> G[N];

ll C(int x,int y){ return f[x] * g[y] % mod * g[x - y] % mod; }

void dfs(int u,int ft){
	ll S = 0; ans[u] = 0;
	dp[u] = f[G[u].size() - (ft ? 1 : 0)];
	for(auto v : G[u]){
		if(v.first != ft){
			dfs(P[v.second] = v.first,u);
//			(ans[u] *= S + 1) %= mod;
//			S += G[v.first].size() - 1;
			dp[u] *= dp[v.first];
		}
	}
//	printf("%d:%lld\n",u,S);
//	for(int i = 0,d = G[u].size() - (ft ? 1 : 0);i < d;++i)
//		(ans[u] += (C(d,i) + (i ? S * C(d - 1,i - 1) % mod : 0)) % mod * f[i] % mod * (d - i) % mod) %= mod;
//		printf("%d-%lld\n",i,f[i]);
}

void dfs2(int u,int ft){
//	printf("%d:%lld %lld\n",u,dp[u],dp2[u]);
	for(auto v : G[u]){
		if(v.first != ft){
			dp2[v.first] = dp2[u] * f[G[u].size() - 1] % mod;
			dfs2(v.first,u);
		}
	}
}

int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	for(int i = f[0] = g[0] = inv[1] = 1;i < N;++i){
		f[i] = f[i - 1] * i % mod;
		if(i >= 2) inv[i] = (mod - mod / i) * inv[mod % i] % mod;
		g[i] = g[i - 1] * inv[i] % mod;
	}
	for(scanf("%d%d",&c,&T);T--;){
		scanf("%d%d",&n,&m);
		for(int i = 1;i <= n;++i) G[i].clear();
		for(int i = 1,u,v;i < n;++i){
			scanf("%d%d",&u,&v);
			G[u].emplace_back(v,i),G[v].emplace_back(u,i);
		}
		dfs(1,0);
		dp2[1] = 1;dfs2(1,0);
		if(19 <= c && c <= 21){
			for(int i = 1,x;i <= m;++i) scanf("%d",&x);
			printf("%lld\n",f[n - 1]);
		} else if(c == 18){
			for(int i = 1,x;i <= m;++i) scanf("%d",&x);
			printf("%lld\n",1);
		} else {
			long long s = 0;
			for(int i = 1,x;i <= m;++i)
				scanf("%d",&x),(s += dp[P[x]] * dp2[P[x]] % mod) %= mod;
			printf("%lld\n",s);
		}
	}
	return 0;
}
