#include<bits/stdc++.h>
#define int long long
inline int read(){
	int x(0),f(1);
	char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(isdigit(ch)) x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x*f;
}
const int MOD=1e9+7,MAXN=1e5+5;
int c,T;
int n,q;
int u[MAXN],v[MAXN],e[MAXN];
inline int C(int n,int m){
	int ret(1);
	for(int i=m-n+1;i<=m;i++) ret=ret*i;
	for(int i=1;i<=n;i++) ret/=i;
	return ret%MOD;
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	c=read(),T=read();
	while(T--){
		n=read(),q=read();
		for(int i=1;i<n;i++) u[i]=read(),v[i]=read();
		for(int i=1;i<=q;i++) e[i]=read();
		std::sort(e+1,e+q+1);
		int tot=std::unique(e+1,e+q+1)-e-1;
		if(c==18){
			printf("%lld\n",1ll);
			continue;
		}
		if(c>=19&&c<=21){
			printf("%lld\n",C(n-1,n*(n-1)/2));
		}
	}
}

