#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7,N=1e5+10;
#define int long long
int n,m,c,t,a[N],Mo[N],ans;
struct node{
	int u,v;
}g[N];
vector<int> e[N];
int dfs(int x,int fa){
	if(e[x].size()==1){
		return 1;
	}
	int s=1;
	for(int i=0;i<e[x].size();i++){
		int y=e[x][i];
		if(y==fa)continue;
		s*=dfs(y,x);
		s%=mod;
	}
	s*=Mo[e[x].size()-1];
	s%=mod;
	return s;
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%lld %lld",&c,&t);
	Mo[0]=1;
	for(int i=1;i<=100000;i++){
		Mo[i]=Mo[i-1]*i%mod;
	}
	while(t--){
		scanf("%lld %lld",&n,&m);
		for(int i=1;i<=n;i++)e[i].clear();
		for(int i=1;i<n;i++){
			scanf("%lld %lld",&g[i].u,&g[i].v);
			e[g[i].u].push_back(g[i].v);
			e[g[i].v].push_back(g[i].u);
		}
		ans=0;
		for(int i=1;i<=m;i++){
			int x;
			scanf("%lld",&x);
			ans+=dfs(g[x].u,g[i].v)*dfs(g[x].v,g[i].u);
		}
		printf("%lld\n",ans);
	}
	return 0;
}
//Forget#2501
