#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
const int mod=1e9+7;
const int inv2=(mod+1)/2;
int type,t,n,k,x,y,e[N],fac[N];
struct node{
	int v,id;
};
vector<node>g[N];
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%d%d",&type,&t);
	fac[0]=1;
	for(int i=1;i<=100000;i++)fac[i]=1ll*fac[i-1]*i%mod;
	while(t--){
		scanf("%d%d",&n,&k);
		for(int i=1;i<=n;i++)g[i].clear();
		for(int i=1;i<n;i++){
			scanf("%d%d",&x,&y);
			g[x].push_back({y,i});
			g[y].push_back({x,i});
		}
		for(int i=1;i<=k;i++)scanf("%d",&e[i]);
		if(type==18)printf("1\n");
		else if(type>=19&&type<=21){
			int ans=fac[n-1]-(1ll*(n-k-1)*(n-k-2)%mod)*fac[n-3]%mod+mod;
			ans=1ll*(ans%mod)*inv2%mod;
			printf("%d\n",ans);
		}else printf("0\n");
	}
	return 0;
}

