#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+10;
const ll mod=1e9+7;
int c,T,n,k,h[N],e[2*N],ne[2*N],idx;
ll ans;
void add(int x,int y){
	e[++idx]=y;
	ne[idx]=h[x];
	h[x]=idx;
}
int 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;
	while(T--){
		cin>>n>>k;
		ans=0;
		for(int i=1;i<n;i++){
			int x,y;
			cin>>x>>y;
			add(x,y);
			add(y,x);
		}
		for(int i=1;i<=k;i++){
			int x;
			cin>>x;
		}
		if(c==18){
			cout<<1<<"\n";
			continue;
		}
		if(c>=19&&c<=21){
			ans=1;
			for(int i=1;i<n-1;i++){
				ans=ans*i%mod;
				if(i==2) ans/=2;
			}
			cout<<ans<<"\n";
			continue;
		}
		cout<<ans<<"\n";
	} 
	return 0;
} 
