#include<bits/stdc++.h>
#define LL long long 
#define Ri register int 
#define ci const int 
using namespace std;
const int N=2e5+15;
const LL mo=1e9+7;
LL fac[N],inv[N],ans,su,inv2[N];
inline LL ksm(LL x,LL y){
	LL res=1;
	while(y>0){
		if(y&1) res=res*x%mo;
		x=x*x%mo;
		y>>=1;
	}
	return res;
}
inline int rd(){
	int ss=0;
	char sp=getchar();
	while(sp>57 || sp<48) sp=getchar();
	while(sp>=48 && sp<=57) ss=(ss<<3)+(ss<<1)+(sp^48),sp=getchar();
	return ss;
}
int n,m,d[N],h[N],cnt=2,vis[N],vis2[N],fa[N],siz[N],Rt,Si,QEQ;
LL f[N];
struct abc{
	int to,nxt,id;
}e[N*2];
void add(int u,int v,int id){
	e[cnt].to=v;
	e[cnt].nxt=h[u];
	e[cnt].id=id;
	h[u]=cnt++;
}
void dfs1(ci s){
	siz[s]=1;
	for(Ri i=h[s]; i!=0; i=e[i].nxt){
		int v=e[i].to;
		if(vis2[v]==1 || v==fa[s]) continue;
		fa[v]=s;
		dfs1(v);
		siz[s]+=siz[v];
	}
	if(Rt==0 && siz[s]>Si/2) Rt=s;
}
void dfs2(ci s){
	for(Ri i=h[s]; i!=0; i=e[i].nxt){
		int v=e[i].to,id=e[i].id;
		if(v==fa[s]) continue;
		if(vis[id]==1) su+=f[s];
		else{
			if(vis2[v]==0){
				f[v]=f[s]*inv2[d[v]-1]%mo;
				fa[v]=s;
				dfs2(v);
			}			
		}
	}
}
void zuo(ci s,ci S){
	Si=S;
	Rt=0;
	fa[s]=0;
	dfs1(s);
	fa[Rt]=0;
	f[Rt]=1;
	su=0;
	dfs1(Rt);
	dfs2(Rt);
	const LL O=(d[Rt]<=2)?1:inv2[d[Rt]-1];
	su%=mo;
	LL res=su*su%mo;
	for(Ri i=h[Rt]; i!=0; i=e[i].nxt){
		int v=e[i].to;
		su=0;
		if(vis[e[i].id]==1) su++;
		else{
			if(vis2[v]==0) dfs2(v);	
		}
		su%=mo;
		res-=su*su%mo;
	}
	res=(res%mo+mo)%mo;
	res=res*O%mo*inv2[2]%mo;
	ans-=res;
	int rt=Rt;
	vis2[Rt]=1;
	for(Ri i=h[rt]; i!=0; i=e[i].nxt){
		int v=e[i].to;
		if(vis2[v]==0) zuo(v,siz[v]);
	}
}
void Sol(){
	n=rd(),m=rd();
	for(Ri i=1; i<=n; ++i) d[i]=vis[i]=h[i]=vis2[i]=fa[i]=siz[i]=f[i]=0;
	cnt=2;
	for(Ri i=1; i<n; ++i){
		int x=rd(),y=rd();
		add(x,y,i),add(y,x,i);
		d[x]++,d[y]++;
	}
	ans=0;
	for(Ri i=1; i<=m; ++i){
		int x=rd();
		vis[x]=1;
		ans++;
	}
	zuo(1,n);
	ans=(ans%mo+mo)%mo;
	for(Ri i=1; i<=n; ++i){
		if(d[i]>=3) ans=ans*fac[d[i]-1]%mo;
	}
	printf("%lld\n",ans%mo);
}
int main(){
//	system("fc traverse.out traverse1.ans");
//	return 0;
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	fac[0]=inv[0]=inv2[0]=1;
	int I=1e5;
	for(Ri i=1; i<=I; ++i) fac[i]=fac[i-1]*i%mo,inv[i]=ksm(fac[i],mo-2),inv2[i]=ksm(i,mo-2);
	int QAQ=rd(),T=rd();
	while(T--) Sol();
}
