#include<cstdio>
#include<vector>
#define N 100005
#define ll long long
using namespace std;

const int p = 1e9+7;

inline ll qpow(ll a, ll b) {
	ll res = 1;
	for(; b; b>>=1, (a*=a)%=p)
		if(b&1)	(res*=a)%=p;
	return res;
}

int c, T, n, k, u[N], v[N], vis[N], siz[N];
ll dp[N], jc[N];
vector<int> e[N];

void dfs(int x) {
	siz[x] = dp[x] = vis[x] = 1;
	for(auto y : e[x]) {
		if(vis[y])	continue;
		siz[x] ++;
		dp[x] = (dp[x]*dp[y])%p;
	}
	ll eds = (1ll*siz[x]*(siz[x]-1)/2)%p;
	dp[x] *= (jc[eds]*qpow(jc[n-1], p-2)%p*qpow(jc[eds-n+1], p-2)%p-n+p)%p;
	dp[x] %= p;
//	printf("- %lld %lld %lld %lld\n", x, dp[x], siz[x], eds);
}

inline void solve18() {
	for(int i=1, ed; i<=k; ++i) {
		scanf("%d", &ed);
	}
	puts("1");
}

inline void solve19() {
	for(int i=1, ed; i<=k; ++i) {
		scanf("%d", &ed);
	}
	--n;
	ll res = qpow(jc[n-1], p-2);
	ll eds = 1ll*n*(n-1)/2;
	eds %= p;
	for(int i=1; i<n; ++i, eds=(eds-1+p)%p)	res = (res*eds)%p;
	printf("%lld\n", (res-n+p)%p);
}

inline void solve() {
	scanf("%d%d", &n, &k);
	for(int i=1; i<=n; ++i)	e[i].clear();
	for(int i=1; i<n; ++i) {
		scanf("%d%d", &u[i], &v[i]);
		e[u[i]].push_back(v[i]), e[v[i]].push_back(u[i]);
	}
	if(c == 18) {
		solve18();
		return;
	}
	if(c >=19 && c<=21) {
		solve19();
		return;
	}
	ll ans = 0;
	for(int i=1, ed; i<=k; ++i) {
		scanf("%d", &ed);
		vis[v[ed]] = 1;
		dfs(u[ed]);
		vis[v[ed]] = 0;
		dfs(v[ed]);
		ans += dp[u[ed]]*dp[v[ed]]%p;
		ans %= p;
		for(int i=1; i<=n; ++i)	vis[i] = siz[i] = dp[i] = 0;
	}
	printf("%lld\n", ans);
}

int main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	jc[1] = 1;
	for(int i=2; i<=N-5; ++i)	jc[i] = (jc[i-1]*i)%p;
	scanf("%d%d", &c, &T);
	while(T--)	solve(); 
	return 0;
}

