#include<bits/stdc++.h>
#define ull  long long
using namespace std;
const long long MOD=1e9+7;
const ull N=1e5;
ull n,k;
ull u,v,e;
ull shu[N];
void workB(){
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<n;i++) scanf("%lld%lld",&u,&v);
	for(int i=1;i<=k;i++) scanf("%lld",&e);
	printf("%lld\n",shu[n-1]*k%MOD);
	return ;
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	ull c,t;
	scanf("%lld%lld",&c,&t);
	shu[1]=1;
	for(int i=2;i<=100005;i++)
		shu[i]=shu[i-1]*i%MOD;
	while(t--) workB();
	return 0;
}
