#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;
const ll MOD=1e9+7; 
const int N=1e5+5;
ll qpow(ll A,ll B)
{
	ll ans=1;
	while(B)
	{
		if(B&1) (ans*=A)%=MOD;
		B>>=1;
		A=A*A%MOD;
	}
	return ans;
}
int c;
vector<vector<int>> G(N);
pair<int,int> edge[N];
int sz[N],fa[N];
ll cnt[N];
int E[N];
//int leaves,leaf;
void dfs(int u,int f)
{
	sz[u]=1,fa[u]=f,cnt[u]=1;
	for(auto v:G[u]){
		if(v==f) continue;
		dfs(v,u);
		sz[u]+=sz[v];
		(cnt[u]*=cnt[v])%=MOD;
	}
	if(u==1) (cnt[u]*=G[u].size())%=MOD;
	else (cnt[u]*=G[u].size()-1)%=MOD;
	if(cnt[u]==0) cnt[u]=1;
//	if(G[u].size()==1) leaves++;
}
//ll qu,qu1;
ll change(int e)
{
	int u=edge[e].fi,v=edge[e].se,tmp=G[1].size()-1;
	ll ans=1;
	if(fa[u]==v) {
		ans=cnt[u];
		ans=ans*(cnt[1]*qpow(cnt[u],MOD-2)%MOD*qpow(G[1].size(),MOD-2)%MOD*(max(tmp,1))%MOD);
	}
	else {
		ans=cnt[v];
		ans=ans*(cnt[1]*qpow(cnt[v],MOD-2)%MOD*qpow(G[1].size(),MOD-2)%MOD*(max(tmp,1))%MOD);
	}
//	if(G[u].size()!=1&&G[v].size()!=1){
//		(qu+=ans*qpow(leaves,MOD-2)%MOD*leaf%MOD)%=MOD;
//	}
//	else {
//		(qu+=ans*=qpow(leaves-1,MOD-2)%MOD*(leaf-1)%MOD*qpow(2,MOD-2)%MOD)%=MOD;
//	}
	return ans;
}
//ll check(int e)
//{
//	int u=edge[e].fi,v=edge[e].se;
//	 
//}
void work()
{
	int n,k;scanf("%d%d",&n,&k);
	
	for(int i=1;i<=n;i++) G[i].clear();
//	leaves=0,leaf=0,qu=0,qu1=0;
	
	for(int i=1;i<n;i++) {
		scanf("%d%d",&edge[i].fi,&edge[i].se);
		G[edge[i].fi].pb(edge[i].se);
		G[edge[i].se].pb(edge[i].fi);
	}
	for(int i=1;i<=k;i++) scanf("%d",&E[i]);
	if(c==18) {printf("1\n");return ;}
	if(19<=c&&c<=21) {
		ll ANS=1,ANS1=1;
		for(int i=n-2;i>=1;i--) (ANS*=i)%=MOD;
		for(int i=n-3;i>=1;i--) (ANS1*=i)%=MOD;
		printf("%lld\n",(ANS*k%MOD-ANS1*k%MOD*(k-1)%MOD*qpow(2,MOD-2)%MOD+MOD)%MOD);
		return ;
	}
	dfs(1,0);
	ll ans=0;
//	for(int i=1;i<=k;i++){
//		cin>>E[i];
//		if(G[edge[E[i]].fi].size()==1||G[edge[E[i]].se].size()==1) leaf++;
//	}
	for(int i=1;i<=k;i++) {
		(ans+=change(E[i]))%=MOD;
	}
	cout<<ans<<endl;
}
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	
	int T;scanf("%d%d",&c,&T);
	while(T--) work();
}
/*
1 1
4 1
1 2
2 3
2 4
1


*/
