#include <bits/stdc++.h>
#define int long long 
using namespace std;
const int N=100005,MOD=1e9+7;
int T,sub,n,k,f[N],x[N],y[N],vis[N],fac[N],ans;
struct node{
	int v,id;
};
vector <node> g[N];
void dfs(int u,int fa){
	int o=0;
	f[u]=1;
	int h=g[u].size()-1;
	for(int i=0;i<g[u].size();i++){
		int v=g[u][i].v;
		if(v==fa)continue;
		if(vis[g[u][i].id]){
			h--;
//			continue;
		}
		dfs(v,u);
		f[u]=f[u]*f[v]%MOD;
	}
//	cout<<h<<" "<<o<<"\n";
	f[u]=f[u]*fac[h]%MOD%MOD;
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	fac[0]=1;
	for(int i=1;i<=100000;i++){
		fac[i]=fac[i-1]*i%MOD;
	}
	cin>>sub>>T;
	while(T--){
		cin>>n>>k;
		//cout<<n<<" "<<k<<" NNN\n";
		for(int i=1;i<n;i++){
			cin>>x[i]>>y[i];
			g[x[i]].push_back(node{y[i],i});
			g[y[i]].push_back(node{x[i],i});
		}
		for(int i=1;i<=k;i++){
			int pp;
			cin>>pp;
			dfs(x[pp],y[pp]);
			//cout<<"???\n";
			dfs(y[pp],x[pp]);
			vis[pp]=1;
			ans=(ans+f[x[pp]]*f[y[pp]]%MOD)%MOD;
			//cout<<x[pp]<<" "<<y[pp]<<" "<<f[x[pp]]<<" "<<f[y[pp]]<<"\n";
		}
		cout<<ans<<"\n";
		ans=0;
		for(int i=1;i<=n;i++){
			g[i].clear();
			vis[i]=0;
		}
	}
}
