#include<bits/stdc++.h>
using namespace std;
#define MAXN 100010
#define mod 1000000007
long long c,t,n,k,u,v,fac[MAXN],cnt,ask[MAXN],to[MAXN<<1],from[MAXN<<1],nxt[MAXN<<1],head[MAXN<<1];
void add(int u,int v){
	to[cnt]=v;
	from[cnt]=u;
	nxt[cnt]=head[u];
	head[u]=++cnt;
}
int mpow(int a,int b){
	int x=1;
	while(b){
		if(b&1)x=x*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return x;
}
int inv(int x){
	return mpow(x,mod-2);
}
void work(){
	scanf("%lld%lld",&n,&k);
	for(int i=0;i<n-1;++i){
		scanf("%lld%lld",&u,&v);
		add(u,v),add(v,u);
	}
	for(int i=0;i<k;++i)scanf("%lld",ask+i);
	fac[1]=1;
	for(int i=2;i<=100000;++i)fac[i]=fac[i-1]*i%mod;
	if(c==18){
		printf("1\n");
		return;
	}
	if(c==19||c==20||c==21){
//		printf("%lld\n",fac[n-1]*inv(fac[n*(n-1)/2])%mod*inv(fac[(n-1)*(n-2)/2])%mod);
		return;
	}
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%lld%lld",&c,&t);
	while(t--){
		work();
		memset(head,0,sizeof(head));
		memset(ask,0,sizeof(ask));
		memset(from,0,sizeof(from));
		memset(to,0,sizeof(to));
		memset(nxt,0,sizeof(nxt));
		cnt=1;
	}
} 
