#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,j,k) for(int i=j;i<=k;++i)
#define g(i,j,k) for(int i=j;i>=k;--i)
int n,m,s,l;
struct IO{const static int N=1<<20,u=3; char a[N];int l,r;char gc(){if(l==r)fread(a,1,u,stdin),l=0,r=u;return a[l++];}}IO;
inline int read(){
	int x=0;char ch=IO.gc();
	for(;'0'>ch||ch>'9';ch=IO.gc());
	for(;'0'<=ch&&ch<='9';ch=IO.gc())x=(x<<3)+(x<<1)+(ch^48);
	return x; 
}
const int N=2e5,mo=1e9+7;
inline void Mul(int&x,int y){x=x*y%mo;} 
struct Kazemaru{
	struct xds{int l,r,c,p,q,t1,t2;}a[N<<2];
	#define mid (a[id].l+a[id].r)/2
	inline void up(int id){
		int u=a[id*2].c,v=a[id*2+1].c,w=a[id].c=min(u,v);
		a[id].c+=a[id].t1;
		a[id].p=a[id].t2*(a[id*2].p+a[id*2+1].p)%mo;
		a[id].q=a[id].t2*((u==w)*a[id*2].q+(v==w)*a[id*2+1].q)%mo;
	}
	inline void Add(int id,int x,int y){a[id].c+=x;a[id].t1+=x;Mul(a[id].p,y);Mul(a[id].q,y);Mul(a[id].t2,y);}
	void bt(int id,int l,int r,int*w){a[id]={l,r,0,w[l],w[l],0,1};if(l<r)bt(id*2,l,mid,w),bt(id*2+1,mid+1,r,w),up(id);}
	void add(int id,int l,int r,int x,int y){
		if(r<a[id].l||a[id].r<l)return;
		if(l<=a[id].l&&a[id].r<=r)return Add(id,x,y);
		add(id*2,l,r,x,y);add(id*2+1,l,r,x,y);up(id);
	}
}T;
inline int ksm(int x,int p=mo-2,int y=1){for(;p;p/=2,x=x*x%mo)if(p&1)y=x*y%mo;return y;}
struct op{int l,r,c;};
vector<op>p[N];vector<int>q[N];
int jc[N],ny[N],v[N],a[N],b[N],c[N],d[N],e[N],L[N],R[N],x,y;
inline void Add(int a,int b,int c,int d){if(a<=b&&c<=d)p[a].push_back({c,d,1}),p[b+1].push_back({c,d,-1});}
void dfs(int x,int fa,int t){
	L[x]=++l;t=t*ny[c[x]]%mo;
	d[l]=q[x].size()<2?t:0;e[x]=fa;
	for(int y:q[x])if(y!=fa)dfs(y,x,t);
	R[x]=l;
}
void dgs(int x,int fa){
	for(op e:p[L[x]])T.add(1,e.l,e.r,e.c,1);
	auto e=T.a[1];if(d[L[x]])m=(m+e.p-(!e.c)*e.q+mo)%mo;
	for(int y:q[x])if(y!=fa){
		int px=c[x],qx=ny[px],py=c[y],qy=ny[py];
		T.add(1,1,n,0,qy);T.add(1,L[y],R[y],0,px*py%mo);
		dgs(y,x);
		T.add(1,1,n,0,py);T.add(1,L[y],R[y],0,qx*qy%mo);
	}
}
inline void doing(){
	n=read();m=read();
	f(i,0,n){
		ny[i]=i?ksm(i):1;
		jc[i]=i?jc[i-1]*i%mo:1;
		v[i]=0;p[i].clear();q[i].clear();
	}
	f(i,2,n){
		a[i]=x=read();b[i]=y=read();
		q[x].push_back(y);
		q[y].push_back(x);
	}
	f(i,1,m)v[read()+1]=1;s=1;
	f(i,1,n)l=q[i].size(),Mul(s,jc[--l]),c[i]=max(l,1ll);
	m=l=0;dfs(1,0,s);T.bt(1,1,n,d);
	f(i,1,n)if(v[i]){
		if(e[x=a[i]]==(y=b[i]))swap(x,y);
		Add(1,L[y]-1,L[y],R[y]);Add(L[y],R[y],R[y]+1,n);
	}
	dgs(1,0);printf("%lld\n",m);
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int c=read(),t=read();
	while(t--)doing(); 
	return 0;
}

