#include<bits/stdc++.h>
using namespace std;
struct node
{
	int u,v;
}a[800001];
const int mod=1e9+7;
int c,T,n,k,location[800001];
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cin >> c >> T;
	while(T--)
	{
		cin >> n >> k;
		int i,j,u,v;
		for(i=1;i<=n-1;i++)
		{
			scanf("%d%d",&a[i].u,&a[i].v);
		}
		for(i=1;i<=k;i++)
		{
			scanf("%d",&location[i]);
		}
		if(c==18)
		{
			printf("1\n");
			continue;
		}
		if(19<=c&&c<=21)
		{
			long long res=1;
			for(i=n-1;i>=1;i--)
			{
				res=(res*i)%mod;
			}
			printf("%lld\n",(res/k)%mod);
			continue;
		}
	}
	return 0;
}
