#include<bits/stdc++.h> 
#define ri register int
#define ll long long
#define mkp make_pair
using namespace std;
const int maxn=1e5+7;
const int mod=1e9+7;
int n,K;
vector<int>vec[maxn];
pair<int,int>edge[maxn];
ll jc[maxn];
bool vis[maxn];
ll res;
void dfs(int u,int fe){
	int cnt=0;
	if(vec[u].size()==1)return;
	for(auto e:vec[u]){
		if(e==fe)continue;
		if(!vis[e])cnt++;
		dfs(u^edge[e].first^edge[e].second,e);
	}
	res=res*cnt%mod*jc[vec[u].size()-2]%mod;
}
void solve(){
	cin>>n>>K;
	for(ri i=1;i<=n;i++)vec[i].clear();
	for(ri i=1;i<n;i++){
		int u,v;cin>>u>>v;
		edge[i]=mkp(u,v);
		vec[u].emplace_back(i);vec[v].emplace_back(i);
	}
	jc[0]=1;for(ri i=1;i<=n;i++)jc[i]=jc[i-1]*i%mod;
	vector<int>impe;
	for(ri i=1;i<=K;i++){
		int x;cin>>x;
		impe.emplace_back(x);
	}
	for(ri i=1;i<n;i++)vis[i]=0;
	ll ans=0;
	for(auto x:impe){
		res=1;
		dfs(edge[x].first,x);
		dfs(edge[x].second,x);
		vis[x]=1;
		ans=(ans+res)%mod;
//		cout<<ans<<endl;
	}
	cout<<ans<<endl;
}
ll qpow(ll a,ll b,ll p){
	ll ans=1;
	for(;b;b>>=1,a=a*a%p)if(b&1)ans=ans*a%p;
	return ans;
}
void solve1(){
	cin>>n>>K;
	for(ri i=1;i<n;i++){
		int u,v;cin>>u>>v;
	}
	for(ri i=1;i<=K;i++){
		int x;cin>>x;
	}
	jc[0]=1;for(ri i=1;i<=n;i++)jc[i]=jc[i-1]*i%mod;
	cout<<(jc[n-1]*qpow(2,mod-2,mod)%mod-1ll*(n-1-K)*(n-1-K-1)%mod*jc[max(n-3,0)]%mod+mod)%mod<<endl;
}
signed main(){
	ios::sync_with_stdio(0);
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int c,T;cin>>c>>T;
	if(c==18){
		while(T--){
			cout<<1<<endl;
		}
		return 0;
	}
	if(c>=19&&c<=21){
		while(T--){
			solve1();
		}
		return 0;
	}
	while(T--)solve();
	return 0;
}
/*
1 1
5 2
2 1
3 1
4 1
5 4
2 4

*/
