#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=1e5+5,MOD=1e9+7;
int to[MAXN<<1],pre[MAXN<<1],hd[MAXN],ec;
int n,q,cid,eu[MAXN],ev[MAXN],p[MAXN];
bool vis[MAXN];
ll fac[MAXN],f[MAXN][2];
void dfs(int u,int fz) {
	int d=0;
	ll p1=1,p2=0;
	for(int i=hd[u];i;i=pre[i]) if(to[i]^fz) {
		int v=to[i]; dfs(v,u),++d;
		if(!vis[i>>1]) {
			p2=(p2*f[v][0]+p1*f[v][1])%MOD;
			p1=p1*f[v][0]%MOD;
		} else {
			p2=p2*f[v][0]%MOD;
			p1=p1*f[v][0]%MOD;
		}
	}
	if(!d) f[u][0]=f[u][1]=1;
	else f[u][0]=p1*fac[d]%MOD,f[u][1]=p2*fac[d-1]%MOD;
}
void solve() {
	cin>>n>>q,ec=1;
	for(int i=1,u,v;i<n;++i) {
		cin>>u>>v,eu[i]=u,ev[i]=v;
		to[++ec]=u,pre[ec]=hd[v],hd[v]=ec;
		to[++ec]=v,pre[ec]=hd[u],hd[u]=ec;
	}
	for(int i=1;i<=q;++i) cin>>p[i];
	if(cid==18) {
		cout<<"1\n";
		return ;
	}
	if(cid==19||cid==20||cid==21) {
		if(n==2) {
			cout<<"1\n";
		} else {
			ll ans=q*fac[n-2]%MOD-1ll*q*(q-1)/2%MOD*fac[n-3]%MOD;
			cout<<(ans+MOD)%MOD<<"\n";
		}
		return ;
	}
	ll ans=0;
	for(int i=1;i<=q;++i) {
		int u=eu[p[i]],v=ev[p[i]];
		dfs(u,v),dfs(v,u);
		ans=(ans+f[u][1]*f[v][1])%MOD;
		vis[p[i]]=true;
	}
	cout<<ans<<"\n";
	for(int i=1;i<=n;++i) hd[i]=vis[i]=0;
}
signed main() {
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	ios::sync_with_stdio(false);
	fac[0]=1;
	for(int i=1;i<MAXN;++i) fac[i]=fac[i-1]*i%MOD;
	int T; cin>>cid>>T;
	while(T--) solve();
	return 0;
}

