#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
const int maxn=1e5+10;
int c,T,n,k,a[maxn],jc[maxn];
vector<int>G[maxn];
int ksm(int x,int y){
	int ret=1;
	while(y){
		if(y&1) ret=ret*x%mod;
		x=x*x%mod,y>>=1;
	}
	return ret;
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%lld%lld",&c,&T);
	jc[0]=1;
	for(int i=1;i<=100000;i++)
		jc[i]=jc[i-1]*i%mod;
	while(T--){
		scanf("%lld%lld",&n,&k);
		for(int i=0;i<=n+1;i++) G[i].clear();
		for(int i=1;i<=n-1;i++){
			int u,v;scanf("%lld%lld",&u,&v);
			G[u].push_back(v),G[v].push_back(u);
		}
		for(int i=1;i<=k;i++)
			scanf("%lld",&a[i]);
		if(c==18){
			printf("1\n");
			continue;
		}
		if(c>=19&&c<=21){
			printf("%lld\n",jc[n-1]);
			continue;
		}
	}
	return 0;
}

