#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using LL=long long;
constexpr int N=1e5+10;
constexpr LL P=1e9+7;
using namespace std;
LL read()
{
	LL x=0;
	int f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())
		if(ch=='-')
			f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())
		x=(x<<1)+(x<<3)+(ch^48);
	return x*f;
}
vector<int>g[N];
void ins(int x,int y)
{
	g[x].emplace_back(y);
}
int n,k;
LL ans=1,siz[N];
LL fac[N];
void dfs(int x,int fa)
{
	
	ans=ans*fac[siz[x]-1]%P;
	for(int &y:g[x])
	{
		if(y==fa)
			continue;
		dfs(y,x);
	}
}
bool v[N];
struct edge
{
	int x,y;
}
a[N];
void prepare()
{
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=fac[i-1]*i%P;
}
void solve()
{
	n=read();k=read();
	prepare();
	for(int i=1,x,y;i<n;i++)
	{
		x=read();
		y=read();
		a[i].x=x;
		a[i].y=y; 
		++siz[x],++siz[y];
		ins(x,y);
		ins(y,x);
	}
	int rt=read();
	dfs(a[rt].x,0);
	printf("%lld\n",ans);
	for(int i=1;i<=n;i++)
		g[i].clear(),siz[i]=0;
}
void solve1()
{
	n=read();
	prepare();
	k=read();
	ans=0;
	for(int i=1,x;i<=k;i++)
	{
		x=read();
		if(!v[x])
			ans=(ans+(fac[n-1]-fac[n-2]*(i-1)%P+P)%P)%P;
		v[x]=1;
	}
	for(int i=1;i<=n;i++)
		v[i]=0;
	printf("%lld\n",ans);
}
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int task,T;
	task=read();T=read();
	while(T--)
	{
		if(task<=6)
			solve();
		else if(task==18)
			printf("%lld\n",1ll);
		else if(task>=19&&task<=21)
			solve1();
	}
	return 0;
}

