#include<bits/stdc++.h>
#define int long long
#define ls(k) (k<<1)
#define rs(k) (k<<1|1)
using namespace std;
const int mod=1e9+7;
const int maxn=1e5+10;
int c,T,n,k,id[maxn];
int du[maxn];
vector<int> G[maxn];
int frc[maxn];
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>c>>T;
	frc[0]=1;
	for (int i=1;i<=100000;i++){
		frc[i]=frc[i-1]*i%mod;
	}
	while (T--){
		cin>>n>>k;
		for (int i=1;i<n;i++){
			int u,v;
			cin>>u>>v;
			G[u].push_back(v);
			G[v].push_back(u);
		}
		for (int i=1;i<=k;i++){
			cin>>id[i];
		}
		if (c==18){
			cout<<1<<'\n';
			continue;
		}
		if (c>=19&&c<=21){
			cout<<frc[k-1]<<'\n';
			continue;
		}
	}
	return 0;
}
/*
19 1
100000 98760
*/
/*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3

*/
