#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
const int mod = 1e9+7;
int n;
vector<int> e[N];
long long lg[N];
void init(){
	lg[0]=lg[1]=1;
	for(int i = 2;i<N;++i){
		lg[i]=lg[i-1]*i%mod;
	}
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int c,T;
	init();
	scanf("%d%d",&c,&T);
	while(T--){
		long long ans=0;
		scanf("%d",&n);
		for(int i = 0;i<=n;++i){
			e[i].clear();
		}
		for(int i = 1;i<n;++i){
			int x,y;
			scanf("%d%d",&x,&y);
			e[x].push_back(y);
			e[y].push_back(x);
		}
		int k;
		scanf("%d",&k);
		while(k--){
			int u;
			scanf("%d",&u);
		}
		ans=1ll*k%mod*lg[n-2]%mod; 
		printf("%lld\n",ans);
	}
	return 0;
}
