#include<algorithm>
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<map>
using namespace std;
const int N=2e5+10,mod=1e9+7;
int read() {
	int s=0; char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') s=10*s+ch-'0',ch=getchar();
	return s;
}
int fac[N],inv[N];
int n,m,a[N],head[N],ver[N],nxt[N],edge[N],tot=1;
void add(int u,int v) {
	ver[++tot]=v; nxt[tot]=head[u]; head[u]=tot;
}
void RD() {
	tot=1;
	n=read(),m=read();
	for(int i=1; i<=n; i++) head[i]=0;
	for(int i=1; i<n; i++) {
		int u=read(),v=read();
		add(u,v),add(v,u);
	}
	for(int i=1; i<=m; i++) a[i]=read();
}
void dfs(int u,int fa) {
	for(int i=head[u]; i; i=nxt[i]) {
		int v=ver[i]; if(v==fa) continue;
		edge[i^1]=1;
		dfs(v,u);
	}
}
void solve() {
	RD();
	int ans=0;
	for(int s=1; s<(1<<m); s++) {
		int kk=__builtin_popcount(s);
		for(int i=1; i<=tot; i++) edge[i]=0;
		for(int j=1; j<=m; j++) if((s>>(j-1))&1) {
			int u=ver[a[j]<<1],v=ver[a[j]<<1^1];
			edge[a[j]<<1]=edge[a[j]<<1^1]=1;
			dfs(u,v),dfs(v,u);
		}
		int res=1;
		for(int u=1; u<=n; u++) {
			int c=0,k=0;
			for(int i=head[u]; i; i=nxt[i]) {
				k++; c+=edge[i];
			}
			if(c==1) res=1ll*res*fac[k-1]%mod;
			else if(c>2) res=0;
			else res=1ll*res*fac[k-2]%mod;
//			printf("u=%d %d %d\n",u,k,c);
		}
		if(kk&1) ans=(ans+res)%mod;
		else ans=(ans-res+mod)%mod;
//		printf("s=%d res=%d\n",s,res);
	}
	printf("%d\n",ans);
}
void solve18() {
	RD();
	printf("1\n");
}
void solve19() {
	RD();
	int ans=1ll*m*fac[n-2]%mod;
	if(n>2) ans=(ans-(1ll*m*(m-1)/2)%mod*fac[n-3]%mod+mod)%mod;
	printf("%d\n",ans);
}
int deg[N]; bool sb[N];
int sumans=0;
void dfs2(int u,int fa,int now) {
	for(int i=head[u]; i; i=nxt[i]) {
		int v=ver[i]; if(v==fa) continue;
		int nx=1ll*now*inv[deg[v]-1]%mod*(sb[i]?1:mod-1)%mod;
		if(sb[i]) sumans=(sumans+nx)%mod;
		dfs2(v,u,nx);
	}
}
void solveall() {
	RD();
	for(int i=1; i<=tot; i++) sb[i]=0;
	for(int i=1; i<=m; i++) sb[a[i]<<1]=sb[a[i]<<1^1]=1;
	int G=1;
	for(int u=1; u<=n; u++) {
		deg[u]=0;
		for(int i=head[u]; i; i=nxt[i]) deg[u]++;
		G=1ll*G*fac[deg[u]-1]%mod;
	}
	sumans=0;
	int ans=1ll*m*G%mod;
	for(int i=1; i<=m; i++) {
		int u=ver[a[i]<<1],v=ver[a[i]<<1^1];
		int tt=1ll*1ll*(mod-1)*inv[deg[u]-1]%mod*inv[deg[v]-1]%mod;
		sumans=0; dfs2(u,v,tt),dfs2(v,u,tt);
		sumans=1ll*sumans*(mod-mod/2)%mod;
		ans=(ans+1ll*sumans*G)%mod;
	}
	printf("%d\n",ans);
}
int main() {
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	fac[0]=inv[1]=1;
	for(int i=1; i<N; i++) fac[i]=1ll*fac[i-1]*i%mod;
	for(int i=2; i<N; i++) inv[i]=1ll*inv[mod%i]*(mod-mod/i)%mod;
	inv[0]=1;
	int c,T; scanf("%d%d",&c,&T);
	for(; T; T--) {
		if(c<=12) solve();
		else if(c==18) solve18();
		else if(c>=19&&c<=21) solve19();
		else solveall();
	}
	return 0;
}
