#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5,P=1e9+7;
ll C,T,n,k,q,fac[N],f[N],ans;
struct xs{
	ll x,y;
}e[N];
vector<ll> g[N];
void dfs(ll u,ll fa){
	f[u]=1;
	for(auto v:g[u]){
		if(v==fa)continue;
		dfs(v,u);
		(f[u]*=f[v])%=P;
	}
	if(g[u].size()>1){
		(f[u]*=fac[g[u].size()-1])%=P;
	}
}
void sol(){
	cin>>n>>k,ans=0;
	for(int i=1;i<=n;i++)g[i].clear();
	for(int i=1;i<n;i++){
		cin>>e[i].x>>e[i].y;
		g[e[i].x].push_back(e[i].y);
		g[e[i].y].push_back(e[i].x);
	}
	for(int i=1;i<=k;i++){
		cin>>q;
		dfs(e[q].x,e[q].y),dfs(e[q].y,e[q].x);
		ll ansx=f[e[q].x],ansy=f[e[q].y];
		(ans+=ansx*ansy)%=P;
	}
	cout<<ans<<'\n';
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	freopen("traverse.in","r",stdin),freopen("traverse.out","w",stdout);
	fac[0]=1;
	for(int i=1;i<=100000;i++){
		fac[i]=fac[i-1]*i%P;
	}
	cin>>C>>T;
	while(T--)sol();
}
