#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=(l);i<=(r);++i)
#define fd(i,l,r) for(int i=(l);i>=(r);--i)
#define fu(i,l,r) for(int i=(l);i<(r);++i)
#define ll long long
using namespace std;
int read(){int s=0;char c=getchar();while(c<48||c>57)c=getchar();while(c>=48&&c<=57)s=(s<<3)+(s<<1)+(c^48),c=getchar();return s;}
const int N=200007,mo=1e9+7,inv2=(mo+1)/2;
int n,o,a[N],b[N],deg[N],k,rt;
ll jc[N],jinv[N],iv[N];
int mod(int x){return x<mo?x:x-mo;}
struct node{
	ll x,y;
	node operator+(const node &t)const{return (node){mod(x+t.x),mod(y+t.y)};}
}f[N],g[N],pre[N],suf[N];
int tot,to[N],head[N],nx[N],w[N];
void add(int x,int y){to[++tot]=y;nx[tot]=head[x];head[x]=tot;}
ll ksm(ll x,int y){ll s=1;for(;y;y>>=1,x=x*x%mo)if(y&1)s=s*x%mo;return s;}
node mer(node u,node v,int o)
{
	return o?u+(node){v.y,v.y}:u+v;
}
void init(int n)
{
	jc[0]=1;fo(i,1,n) jc[i]=jc[i-1]*i%mo;
	jinv[n]=ksm(jc[n],mo-2);fd(i,n,1) jinv[i-1]=jinv[i]*i%mo;
	fo(i,1,n) iv[i]=jinv[i]*jc[i-1]%mo;
}
void dfs(int x,int y)
{
	f[x]=(node){0,0};
	int cnt=0;
	for(int i=head[x],j;i;i=nx[i])
	{
		j=to[i];if(j==y) continue;
		dfs(j,x);cnt++;
		f[x]=mer(f[x],f[j],w[i]);
	}
	if(!cnt) f[x]=(node){0,1};
	else f[x].x=f[x].x*iv[deg[x]-1]%mo,f[x].y=f[x].y*iv[deg[x]-1]%mo;
}
void dfs2(int x,int y)
{
	o=0;
	for(int i=head[x],j;i;i=nx[i])
	{
		j=to[i];if(j==y) continue;
		a[++o]=j;b[o]=w[i];
	}
	pre[0]=g[x];
	suf[o+1]=(node){0,0};
	fo(i,1,o) pre[i]=mer(pre[i-1],f[a[i]],b[i]);
	fd(i,o,1) suf[i]=mer(suf[i+1],f[a[i]],b[i]);
	fo(i,1,o)
	{
		g[a[i]]=pre[i-1]+suf[i+1];
		if(b[i]) g[a[i]].x=g[a[i]].y;
		int u=deg[x];
		g[a[i]].x=g[a[i]].x*iv[u-1]%mo;
		g[a[i]].y=g[a[i]].y*iv[u-1]%mo;
	}
	for(int i=head[x],j;i;i=nx[i])
	{
		j=to[i];if(j==y) continue;
		dfs2(j,x);
	}
}
void work()
{
	n=read();k=read();
	fo(i,1,n) deg[i]=head[i]=0;
	fo(i,0,n+n) w[i]=0;
	tot=0;
	fu(i,1,n)
	{
		int x,y;x=read();y=read();
		add(x,y);add(y,x);
		deg[x]++;deg[y]++;
	}
	fo(i,1,k)
	{
		int x;x=read();
		w[x+x-1]=w[x+x]=1;
	}
	if(n==2)
	{
		printf("1\n");
		return;
	}
	rt=0;
	fo(i,1,n) if(deg[i]>1) rt=i;
	dfs(rt,0);
	g[rt]=(node){0,0};
	dfs2(rt,0);
	ll ans=0;
	fo(i,1,n) if(deg[i]==1) ans=(ans+g[i].x)%mo;
	ans=ans*inv2%mo;
	fo(i,1,n) ans=ans*jc[deg[i]-1]%mo;
	printf("%lld\n",ans);
}
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	init(N-1);
	int T;scanf("%*d%d",&T);
	while(T--) work();
}
