#pragma GCC optimize("2")
#include<bits/stdc++.h>
#define N 100010
using namespace std;
inline bool Isdigit(char c){return c>='0'&&c<='9';}
template<typename T>inline void read(T &x){
	x=0;char c=getchar();bool f=0;
	while(!Isdigit(c)){if(c=='-')f=1;c=getchar();}
	while(Isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
	x=f?-x:x;
}
const int Mod=1e9+7,Inv=5e8+4;
inline int Qpow(int a,int b){
	int Res=1;
	while(b){
		if(b&1)Res=1LL*Res*a%Mod;
		a=1LL*a*a%Mod;
		b>>=1;
	}
	return Res;
}
int c,T,n,K,cnt,tot,u[N],v[N],fac[N],dep[N],Id[N];
int f[N],g[N],Pre[N],Suf[N],vis[N],Num[N],head[N],To[N<<1],Nxt[N<<1];
void Pre_Solve(int n){
	fac[0]=fac[1]=1;
	for(int i=2;i<=n;i++)
		fac[i]=1LL*fac[i-1]*i%Mod;
}
void Init(){
	cnt=0;
	for(int i=1;i<=n;i++)
		head[i]=0;
}
void add(int from,int to){
	To[++cnt]=to;
	Nxt[cnt]=head[from];
	head[from]=cnt;
}
void Dfs(int now,int fa){
	dep[now]=dep[fa]+1;
	for(int i=head[now];i;i=Nxt[i])
		if(To[i]^fa)Dfs(To[i],now);
}
void Solve(int k){
	for(int i=1;i<=n;i++)vis[i]=false;
	for(int i=1;i<k;i++)
		vis[dep[u[Id[i]]]>dep[v[Id[i]]]?u[Id[i]]:v[Id[i]]]=true;
}
void dfs(int now,int fa){
	Num[now]=1;
	int Siz=0;
	for(int i=head[now];i;i=Nxt[i])
		if(To[i]^fa)Siz++;
	if(!Siz)return ;
	for(int i=head[now];i;i=Nxt[i])
		if(To[i]^fa){
			dfs(To[i],now);
			Num[now]=1LL*Num[now]*Num[To[i]]%Mod;
		}
	g[now]=Num[now];
	Num[now]=1LL*Num[now]*fac[Siz]%Mod;
}
void _dfs(int now,int fa){
	int Siz=0;
	for(int i=head[now];i;i=Nxt[i])
		if(To[i]^fa)Siz++;
	if(!Siz)return ;
	Pre[0]=Suf[Siz+1]=1;
	for(int i=head[now],j=1;i;i=Nxt[i],j++)
		if(To[i]==fa)--j;
		else Pre[j]=Suf[j]=Num[To[i]];
	for(int i=1;i<=Siz;i++)Pre[i]=1LL*Pre[i-1]*Pre[i]%Mod;
	for(int i=Siz;i>=1;i--)Suf[i]=1LL*Suf[i+1]*Suf[i]%Mod;
	for(int i=head[now],j=1;i;i=Nxt[i],j++)
		if(To[i]==fa)--j;
		else f[To[i]]=1LL*f[now]*fac[Siz-1]%Mod*Pre[j-1]%Mod*Suf[j+1]%Mod;
	for(int i=head[now];i;i=Nxt[i])
		if(To[i]^fa){
			if(vis[To[i]])(tot+=1LL*f[To[i]]*Num[To[i]]%Mod)%=Mod;
			else _dfs(To[i],now);
		}
}
namespace Sub2{void Solve(){int x;while(K--)read(x);return puts("1"),void();}}
namespace Sub3{
	void Solve(){
		int x;for(int i=1;i<=K;i++)read(x);
		int Res=0;
		if(n<3)return puts("1"),void();
		for(int i=1;i<=K;i++)
			(Res+=1LL*(n-i-1)*fac[n-3]%Mod)%=Mod;
		printf("%d\n",Res);
	}
}
void Solve(){
	read(n),read(K),Init();
	for(int i=1;i<n;i++){
		read(u[i]),read(v[i]);
		add(u[i],v[i]),add(v[i],u[i]);
	}
	if(c==18)return Sub2::Solve(),void();
	if(c>=19&&c<=21)return Sub3::Solve(),void();
	int Res=0;
	for(int i=1;i<=K;i++){
		read(Id[i]);
		Dfs(u[Id[i]],0);
		Solve(i);
		f[u[Id[i]]]=f[v[Id[i]]]=1;
		dfs(u[Id[i]],v[Id[i]]);
		_dfs(u[Id[i]],v[Id[i]]);
		int totx=tot;tot=0;
		dfs(v[Id[i]],u[Id[i]]);
		_dfs(v[Id[i]],u[Id[i]]);
		int toty=tot;tot=0;
		// cout<<u[Id[i]]<<" "<<v[Id[i]]<<endl;
		// cout<<Num[u[Id[i]]]<<" "<<Num[v[Id[i]]]<<endl;
		// cout<<totx<<" "<<toty<<endl;
		// Res=(Res-1LL*totx*Num[v[Id[i]]]%Mod+Mod)%Mod;
		// Res=(Res-1LL*toty*Num[u[Id[i]]]%Mod+Mod)%Mod;
		(Res+=1LL*(Num[u[Id[i]]]-totx+Mod)%Mod*(Num[v[Id[i]]]-toty+Mod)%Mod)%=Mod;
	}
	printf("%d\n",Res);
	// cout<<"\n\n\n\n";
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	Pre_Solve(N-10);
	read(c),read(T);
	while(T--)Solve();
}