#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
struct sbq{
	int x,y;
}a[100005];
long long jc[100005],ny[100005],h[100005],nh[100005],nhh[100005],hh[100005],sum;
long long s1,s2;
int fir[100005],nex[200005],to[200005],tot=0,d[100005],dp[100005];
int fa[100005],u[100005],f[100005];
void add(int x,int y){nex[++tot]=fir[x],to[tot]=y,fir[x]=tot;}
int po(int x,int t){
	int p=1;
	while(t){
		if(t&1) p=p*1ll*x%mod;
		x=x*1ll*x%mod,t>>=1;
	}
	return p;
}
void dfs(int t){
	hh[t]=hh[fa[t]]*jc[max(d[t]-2,0)]%mod;
	nhh[t]=po(hh[t],mod-2);
	h[t]=h[fa[t]]*jc[d[t]-1]%mod;
	nh[t]=po(h[t],mod-2);
	for(int i=fir[t];i;i=nex[i]){
		if(to[i]==fa[t]) continue;
		dp[to[i]]=dp[t]+1,fa[to[i]]=t;dfs(to[i]);
	}
}
int lca(int x,int y){
	if(f[y]) return x;
	if(dp[x]<dp[y]){
		while(dp[y]>dp[x]){
			if(f[y])
				return x;
			f[y]=1,s1=s1*jc[d[y]-1]%mod,s2=s2*jc[max(d[y]-2,0)]%mod;
			y=fa[y];
		}
		while(x!=y){
			x=fa[x];
			f[x]=1,s1=s1*jc[d[x]-1]%mod,s2=s2*jc[max(d[x]-2,0)]%mod;
			y=fa[y];if(x==y) return x;
			f[y]=1,s1=s1*jc[d[y]-1]%mod,s2=s2*jc[max(d[y]-2,0)]%mod;
		}
	}
	else{
		while(dp[x]>dp[y]){
			x=fa[x];
			f[x]=1,s1=s1*jc[d[x]-1]%mod,s2=s2*jc[max(d[x]-2,0)]%mod;
		}
		if(f[y]) return x;
		f[y]=1,s1=s1*jc[d[y]-1]%mod,s2=s2*jc[max(d[y]-2,0)]%mod;
		while(x!=y){
			x=fa[x];
			f[x]=1,s1=s1*jc[d[x]-1]%mod,s2=s2*jc[max(d[x]-2,0)]%mod;
			y=fa[y];if(x==y) return x;
			f[y]=1,s1=s1*jc[d[y]-1]%mod,s2=s2*jc[max(d[y]-2,0)]%mod;
		}
	}
	return x;
}
int lcaa(int x,int y){
	if(dp[x]>dp[y]) swap(x,y);
	while(dp[y]>dp[x]) y=fa[y];
	while(x!=y) x=fa[x],y=fa[y];
	return x;
}
long long qz(int x,int y,int lc){
	long long lj=h[x]*h[y]%mod*nh[fa[lc]]%mod*nh[lc]%mod;
	long long llj=hh[x]*hh[y]%mod*nhh[fa[lc]]%mod*nhh[lc]%mod;
	return po(lj,mod-2)*1ll*(lj-llj)%mod;
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	jc[0]=1;for(int i=1;i<=100000;i++) jc[i]=jc[i-1]*i%mod;
	ny[100000]=po(jc[100000],mod-2);for(int i=99999;i>=0;i--) ny[i]=ny[i+1]*(i+1)%mod;
	int id,uuu;scanf("%d%d",&id,&uuu);
	while(uuu--){
		int n,k;scanf("%d%d",&n,&k);tot=0;
		for(int i=1;i<=n;i++) fir[i]=d[i]=f[i]=0;
		for(int i=1;i<n;i++){
			scanf("%d%d",&a[i].x,&a[i].y);
			add(a[i].x,a[i].y),add(a[i].y,a[i].x);
			d[a[i].x]++,d[a[i].y]++;
		}
		h[0]=nh[0]=hh[0]=nhh[0]=1,dfs(1);
		for(int i=1;i<n;i++) if(dp[a[i].x]>dp[a[i].y]) swap(a[i].x,a[i].y);
		sum=1;for(int i=1;i<=n;i++) sum=sum*jc[d[i]-1]%mod;
		s1=s2=1;
		long long ans=0;
		int la=0;
		if(k==1)
		for(int i=1;i<=k;i++){
			scanf("%d",&u[i]);
			if(i==1){
				ans=(ans+sum)%mod,la=a[u[i]].x;
				f[la]=1,s1=s1*jc[d[la]-1]%mod,s2=s2*jc[max(d[la]-2,0)]%mod;
			}
			else{
				la=lca(la,a[u[i]].x);
				ans=(ans+sum*po(s1,mod-2)%mod*(s1-s2)%mod)%mod;
			}
		}
		else 
		for(int i=1;i<=k;i++){
			scanf("%d",&u[i]);
			if(i==1) ans=(ans+sum)%mod;
			else
			ans=(ans+sum*qz(a[u[i]].x,a[u[i-1]].x,lcaa(a[u[i]].x,a[u[i-1]].x))%mod)%mod;
		}
		printf("%lld\n",(ans+mod)%mod);
	}
	return 0;
}
