#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
int c,T,n,k,imp[100005],fac[100005],inv[100005];
inline int ksm(int a,int b){
	int tmp=1;
	while(b){
		if(b&1)tmp=tmp*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return tmp;
}
inline int C(int a,int b){
	if(b>a)return 0;
	return fac[a]*inv[a-b]%mod*inv[b]%mod;
}

signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>c>>T;
	fac[0]=1;
	for(int i=1;i<=100000;i++)fac[i]=fac[i-1]*i%mod;
	inv[100000]=ksm(fac[100000],mod-2);
	for(int i=100000-1;~i;i--)inv[i]=inv[i+1]*(i+1)%mod;
	while(T--){
		cin>>n>>k;
//		vector<int>edge[100005];
//		vector<int>new_edge[100005];
		for(int i=1;i<n;i++){
			int u,v;
			cin>>u>>v;
//			edge[u].push_back(v);
//			edge[v].push_back(u);
		}
		for(int i=1;i<=k;i++){
			int p;cin>>p;
			imp[p]=1;
		}
		if(c==18){
			cout<<"1\n";
		}
		if((c>=19&&c<=21)||(c<=3)){
			int ans=fac[n-1]*inv[2]%mod;
			ans=(ans-fac[n-3]*C(n-k-1,2)%mod+mod)%mod;
			cout<<ans<<'\n';
		}
	}
	return 0;
}

