#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 500005
#define md 1000000007
ll c,t,n,k,head[N],tot,bj[N],jc[N];
struct EDGE{ll v,nt,z;} edge[N*2];
void addedge(ll x,ll y,ll z){
	edge[tot].v=y,edge[tot].z=z,edge[tot].nt=head[x],head[x]=tot++;
	edge[tot].v=x,edge[tot].z=z,edge[tot].nt=head[y],head[y]=tot++;
}
void b(ll w,ll f){
//	cout<<w<<" "<<f<<endl;
	for(int i=head[w];i;i=edge[i].nt){
		ll y=edge[i].v;
		if(y==f)continue;
		bj[edge[i].z]=y;
//		cout<<y<<" "<<edge[i].z<<endl;
		b(y,w);
	}
	return ;
}
ll dfs(ll w,ll v){
	ll ans=1,o=0;
	for(int i=head[w];i;i=edge[i].nt,++o){
		ll y=edge[i].nt;
		if(y==v) continue;
		ans=ans*dfs(y,w)%md;
	}
	return ans*jc[o];
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cin>>c>>t;
	for(ll tt=1;tt<=t;tt++){
		cin>>n>>k;
		memset(head,0,sizeof(head)),tot=1;
		jc[0]=1;
		for(int i=1,x,y;i<n;i++) cin>>x>>y,addedge(x,y,i),jc[i]=jc[i-1]*i%md;
		b(1,0);
		ll ans=0;
		for(int i=1,v;i<=k;i++) cin>>v,ans+=dfs(bj[v],0);
		cout<<ans<<endl;
	}
	return 0;
}
