#include<bits/stdc++.h>
using namespace std;
namespace MAOJUN{

typedef long long ll;
const int N=1e5+5,MOD=1e9+7,i2=MOD+1>>1;
int n,k,dg[N];
const int E=N<<1;
int tot,hd[N],to[E],nxt[E];
inline void Add(int u,int v){to[++tot]=v;nxt[tot]=hd[u];hd[u]=tot;dg[v]++;}
ll F[N],I[N];bool fl[N];

int fa[N],ps[N],dep[N];
void dfs1(int u,int f){
	fa[u]=f;dep[u]=dep[f]+1;
	for(int i=hd[u];i;i=nxt[i])if(to[i]!=f)dfs1(to[i],u);
}
int A[N];ll rs;
int al,mn,wc,sz[N];bool vs[N];
void gwc(int u,int f){
	sz[u]=1;int mx=0;
	for(int i=hd[u];i;i=nxt[i]){
		int v=to[i];if(v==f||vs[v])continue;
		gwc(v,u);sz[u]+=sz[v];mx=max(mx,sz[v]);
	}
	mx=max(mx,al-sz[u]);if(mx<mn){mn=mx;wc=u;}
}
#define _dvd(u,s) {al=mn=s;gwc(u,0);dvd(wc);}
ll S,T;
void dfs(int u,int ie,ll w){
	if(fl[ie>>1]){T=(T+w)%MOD;return;}
	w=w*A[u]%MOD;
	for(int i=hd[u];i;i=nxt[i])if(ie^i^1){
		int v=to[i];if(!vs[v])dfs(v,i,w);
	}
}
void dvd(int u){
	vs[u]=1;gwc(u,0);S=0;
	for(int i=hd[u];i;i=nxt[i]){
		int v=to[i];if(vs[v])continue;
		T=0;dfs(v,i,1);rs=(rs-S*T%MOD*A[u])%MOD;
		S=(S+T)%MOD;
	}
	for(int i=hd[u];i;i=nxt[i])if(!vs[to[i]])_dvd(to[i],sz[to[i]]);
}
inline void slv(){
	scanf("%d%d",&n,&k);
	tot=1;memset(hd,0,sizeof hd);memset(dg,0,sizeof dg);
	for(int i=1,u,v;i<n;i++){scanf("%d%d",&u,&v);Add(u,v);Add(v,u);}
	for(int i=1;i<=n;i++)A[i]=I[dg[i]-1];
	memset(fl,0,sizeof fl);
	dfs1(1,0);
	for(int i=1,x;i<=k;i++){
		scanf("%d",&x);//fl[x]=1;
		int u=to[x<<1],v=to[x<<1|1];
		ps[i]=fa[u]==v?u:v;fl[ps[i]]=1;
	}
	memset(vs,0,sizeof vs);
	rs=k;//_dvd(1,n);rs=(rs+MOD)%MOD;
	for(int i=1;i<=k;i++)for(int j=1;j<i;j++){
		int u=ps[i],v=ps[j];
		if(dep[u]<dep[v])swap(u,v);
		ll vl=1;
		while(dep[u]>dep[v]){
			u=fa[u];vl=vl*A[u]%MOD;
			if(u!=v&&fl[u])vl=0;
		}
		while(u!=v){
			u=fa[u];v=fa[v];
			vl=vl*A[u]%MOD;
			if(u!=v){
				vl=vl*A[v]%MOD;if(fl[u]||fl[v])vl=0;
			}
		}
		rs-=vl;
	}
	rs=(rs%MOD+MOD)%MOD;
	for(int i=1;i<=n;i++)rs=rs*F[dg[i]-1]%MOD;
	printf("%lld\n",rs);
}
inline void main(){
	F[0]=1;for(int i=1;i<N;i++)F[i]=F[i-1]*i%MOD;
	I[1]=1;for(int i=2;i<N;i++)I[i]=I[MOD%i]*(MOD-MOD/i)%MOD;
	int c,T;scanf("%d%d",&c,&T);while(T--)slv();
}

}int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	MAOJUN::main();
	return 0;
}