#include<bits/stdc++.h>
using namespace std;

const int mod=1e9+7;
long long c,T;
long long n,k;
vector<int> v[100005];
long long from[100005];
long long to[100005];
long long e[100005];
long long user[100005];
long long vis[100005];
long long cnt=0;

void dfs(long long begin){
	vis[begin]=1;
	if(v[begin].size()==1 && vis[v[begin][0]]==1){
		user[begin]=1;
		return;
	}
	long long check=0;
	for(int i=0;i<v[begin].size();i++){
		if(vis[v[begin][i]]==0){
			dfs(v[begin][i]);	
			user[begin]*=(user[v[begin][i]]+check); 
			user[begin]%=mod;
			check++;
		}
	}
	return;
}

int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cin>>c>>T;
	while(T--){
		scanf("%lld %lld",&n,&k);
		memset(from,0,sizeof(from)); memset(to,0,sizeof(to)); 
		memset(user,0,sizeof(user)); memset(vis,0,sizeof(vis));
		memset(e,0,sizeof(e));
		for(int i=1;i<=n;i++) v[i].clear();
		for(int i=1;i<=n-1;i++){
			long long ua,ub; scanf("%lld %lld",&ua,&ub);
			from[i]=ua; to[i]=ub;
			v[ua].push_back(ub);
			v[ub].push_back(ua);
			user[i]=1;
		}user[n]=1;
		for(int i=1;i<=k;i++){
			scanf("%lld",&e[i]);
		}
		vis[to[e[1]]]=1;
		dfs(from[e[1]]);
		memset(vis,0,sizeof(vis)); 
		vis[from[e[1]]]=1;
		dfs(to[e[1]]);
		printf("%lld\n",user[from[e[1]]]%mod*user[to[e[1]]]%mod);
	}
	return 0;
} 

