#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define ll long long
const int N=1e5+10;
const ll M=1e9+7;
ll js[N],njs[N],ans,cur,mi2,dp[N][2],siz[N];
int c,T,n,k,i,idx,head[N],nxt[N<<1],to[N<<1],d[N],u,v;
bool e[N],h[N];
void add(int x,int y){
	to[++idx]=y,nxt[idx]=head[x],head[x]=idx;
}
ll mi(ll a,ll b){
	ll ans=1;
	while(b){
		if(b&1) ans=ans*a%M;
		a=a*a%M;
		b>>=1;
	}
	return ans;
}
void dfs(int u,int f){
	for(int i=head[u];i;i=nxt[i]){
		int v=to[i];
		if(v!=f){
			if(e[i/2]) h[v]=1;
			dfs(v,u);
			if(h[v]) h[u]=1;
			++d[u];
		}
	}
	if(u!=1) cur=cur*js[d[u]]%M;
}
void dfs2(int u,int f){
	int cnt=d[u];
	ll curans=1;
	if(u==1){
		curans=cur;
	}else{
		curans=cur*njs[d[u]]%M;
	}
	for(int i=head[u];i;i=nxt[i]){
		int v=to[i];
		if(v==f) continue;
		dfs2(v,u);
		if(!h[v]) continue;
		--cnt;
		if(cnt==0) continue;
		if(u!=1) ans=(ans+curans*js[d[u]-2]%M*cnt%M*js[d[1]-1]%M)%M;
		else ans=(ans+curans*js[d[1]-2]%M*cnt%M)%M;
	}
	if(u==1&&d[u]==1) ans=(ans+curans)%M;
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%d%d",&c,&T);
	for(i=js[0]=1;i<N;++i){
		js[i]=js[i-1]*i%M;
		njs[i]=mi(js[i],M-2);
	}
	mi2=mi(2,M-2);
	while(T--){
		scanf("%d%d",&n,&k);
		idx=1,ans=0,cur=1;
		memset(head,0,sizeof(head));
		memset(e,0,sizeof(e));
		memset(h,0,sizeof(h));
		memset(d,0,sizeof(d));
		for(i=1;i<n;++i){
			scanf("%d%d",&u,&v);
			add(u,v),add(v,u);
		}
		for(i=1;i<=k;++i){
			scanf("%d",&u);
			e[u]=1;
		}
		dfs(1,0);
		dfs2(1,0);
		printf("%lld\n",ans);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}

