#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+10,p=1e9+7;
ll c,T,n,k,f[N],d[N],g[N],fa[N],fd[N],s[N],pre[N],suf[N],tn[N];
struct edge{
	ll u,v;
}e[N];
vector<ll>G[N];
inline bool dfs(ll u,ll p){
	d[u]=d[p]+1;
	fa[u]=p;
	f[u]=s[G[u].size()-1];
	if(G[u].size()==1) return 0;
	for(ll i=0;i<G[u].size();i++){
		ll v=G[u][i];
		if(v==p){
			fd[u]=i;
			continue;
		}
		if(dfs(v,u)) f[u]=f[u]*2%p*f[v]%p;
	}
	return 1;
}
inline void dfs2(ll u,ll p,bool t){
	int k=1<<t;
	pre[0]=suf[G[u].size()+1]=1;
	for(ll i=0;i<G[u].size();i++){
		int v=G[u][i];
		if(v==p) pre[i+1]=pre[i]*g[v]%p;
		else{
			pre[i+1]=pre[i]*f[v]%p;
			if(G[v].size()!=1) k=k*2%p,tn[v]=2;
			else tn[v]=1;
		}
	}
	for(ll i=G[u].size()-1;i>=0;i--){
		if(G[u][i]==p) suf[i+1]=suf[i+2]*g[G[u][i]]%p;
		else suf[i+1]=suf[i+2]*f[G[u][i]]%p;
	}
	for(ll i=0;i<G[u].size();i++){
		ll v=G[u][i];
		if(v==p) continue;
		g[v]=pre[i]*suf[i+2]%p*s[G[u].size()-1]%p*k/tn[v];
		dfs2(v,u,bool(G[u].size()-1));
	}
}
int main(){
	ios::sync_with_stdio(0);
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cin>>c>>T;
	s[0]=1;
	for(ll i=1;i<=100010;i++) s[i]=s[i-1]*i%p;
	while(T--){
		ll ans=0;
		cin>>n>>k;
		for(ll i=1;i<n;i++){
			cin>>e[i].u>>e[i].v;
			G[e[i].u].push_back(e[i].v);
			G[e[i].v].push_back(e[i].u);
		}
		dfs(1,0);
		dfs2(1,0,0);
		while(k--){
			ll id;
			int u=e[id].u,v=e[id].v;
			cin>>id;
			if(d[u]>d[v]) swap(u,v);
			ans=(ans+2*f[v]%p*g[u]%p)%p;
		}
		cout<<ans<<'\n';
	}
	return 0;
}
