#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define oF(l,r,i) for(int i=l;i<=r;i++)
#define of(l,r) oF(l,r,i)
#define tF(n,i) oF(1,n,i)
#define tf(n) tF(n,i)
#define nF(i) tF(n,i)
#define nf() nF(i)
#define mF(i) tF(m,i)
#define mf() mF(i)
#define pint pair<int,int>
#define mp make_pair
#define f first
#define s second
#define fin(x) freopen(#x".in","r",stdin)
#define fout(x) freopen(#x".out","w",stdout)
#define file(x) (fin(x),fout(x))
#define Read(x) (fin(x),read())
#define READ(x) (file(x),read())
ll read(){
	int x=0;
	char c=getchar();
	while(c<48||c>57)c=getchar();
	while(c>47&&c<58){
		x=(x<<1)+(x<<3)+(c^48);
		c=getchar();
	}
	return x;
}
void write(ll x){
	if(x>9ll)write(x/10);
	putchar(x%10|48);
}
char gtch(){
	char c=getchar();
	while(c<33)c=getchar();
	return c;
}
#define mod 1000000007
#define inv2 500000004
int fac[500005],invf[500005],inv[500005];
//int c=read();
//int c=Read(traverse1);
int c=READ(traverse);
int T=read();
int h[500005],nxt[1000005],to[1000005],d[500005],idx;
void add(int x,int y){
	to[++idx]=y;
	nxt[idx]=h[x];
	h[x]=idx;
	d[x]++;
}
int fa[500005],v[500005],sv[500005],p[500005];
int st[500005],tp;
void dfs(int x){
	st[++tp]=x;
	int btp=0;
	while(btp^tp){
		int x=st[++btp];
		for(int ep=h[x];ep;ep=nxt[ep]){
			if(to[ep]^fa[x]){
				fa[to[ep]]=x;
				st[++tp]=(to[ep]);
			}
		}
	}
	tp=0;
}
void vdfs(int x){
	st[++tp]=x;
	int btp=0;
	while(btp^tp){
		int x=st[++btp];
		sv[x]=v[x];
		for(int ep=h[x];ep;ep=nxt[ep]){
			if(to[ep]^fa[x]){
				st[++tp]=(to[ep]);
			}
		}
	}
	while(tp){
		int x=st[tp--];
		sv[fa[x]]+=sv[x];
	}
}
void adfs(int x){
	st[++tp]=x;
	int btp=0;
	while(btp^tp){
		int x=st[++btp];
		for(int ep=h[x];ep;ep=nxt[ep]){
			if(to[ep]^fa[x]){
				if(sv[1]-sv[to[ep]]+v[to[ep]])p[to[ep]]++;
				if(to[ep][sv])p[x]++;
				st[++tp]=(to[ep]);
			}
		}
	}
	tp=0;
}
void solve(){
	int n=read(),m=read();
	idx=1;
	nf()h[i]=d[i]=p[i]=v[i]=0;
	tf(n-1){
		int x=read(),y=read();
		add(x,y);
		add(y,x);
	}
	dfs(1);
	mf(){
		int k=read();
		int x=to[k<<1],y=to[k<<1|1];
		if(fa[y]==x)swap(x,y);
		v[x]=1;
	}
	vdfs(1);
	adfs(1);
	int ans=1;
	nf(){
		if(d[i]>1){
			(ans*=(fac[d[i]-2]*(p[i]*((d[i]<<1)-p[i]-1)%mod)%mod*inv2)%mod)%=mod;
//			cerr<<i<<' '<<d[i]<<' '<<p[i]<<' '<<fac[d[i]-2]*(p[i]*((d[i]<<1)-p[i]-1)%mod)%mod<<'\n';
		}
	}
	write(ans);putchar(10);
}
signed main(){
	fac[0]=1;
	tf(500000)fac[i]=fac[i-1]*i%mod;
	while(T--)solve();//40pts
}
//May all the beauty be blessed
