#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
const ll N=100005,mod=1000000007;
ll id,tn,pn,bn,cnt=1,shan,jc[N],first[N];
struct Bian{
	ll to,next;
}b[N*2];
void add(ll from,ll to){
	cnt++;
	b[cnt].to=to;
	b[cnt].next=first[from];
	first[from]=cnt;
}
ll ksm(ll ds,ll cf){
	ll cnt=1;
	while(cf!=0){
		if(cf%2==1){
			cnt=cnt*ds%mod;
		}
		ds=ds*ds%mod;
		cf/=2;
	}
	return cnt;
}
ll cha(ll now,ll f){
//	printf("%lld %lld\n",now,f);
	ll cnt=1,ls=0;
	for(ll i=first[now];i!=0;i=b[i].next){
		if(i!=shan && (i^1)!=shan && b[i].to!=f){
			cnt=cnt*cha(b[i].to,now);
			ls++;
		}
	}
	if(ls==0){
		return 1;
	}
	return cnt*jc[ls]%mod*ksm(jc[ls-1],mod-2)%mod;
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	jc[0]=1;
	for(ll i=1;i<N;i++){
		jc[i]=jc[i-1]*i%mod;
	}
	scanf("%lld%lld",&id,&tn);
	for(;tn>0;tn--){
		ll ans=0;
		cnt=1;
		memset(first,0,sizeof(first));
		scanf("%lld%lld",&pn,&bn);
		for(ll i=1;i<pn;i++){
			ll from,to;
			scanf("%lld%lld",&from,&to);
			add(from,to);
			add(to,from);
		}
		for(ll i=0;i<bn;i++){
			scanf("%lld",&shan);
			shan*=2;
			if(id<=17 || id>=22){
				ans=(ans+cha(b[shan].to,0)*cha(b[shan^1].to,0)%mod)%mod;
			}
		}
		if(id==18){
			printf("1\n");
			continue;
		}else if(id>=19 && id<=21){
			printf("%lld\n",jc[pn-2]*ksm(jc[pn-3],mod-2)%mod);
			continue;
		}
		printf("%lld\n",ans);
	}
	return 0;
}
