#include<bits/stdc++.h>
using namespace std;
#define int long long
const int x=pow(10,9)+ 7;
struct node{
	int from,to;
	int nfr,nto;bool eeeee=false;
}bian[200500];
int c,T,n,k,u[200500],e[200500],ton[200500];
int jiec(int a){
	int y=1;
	for(int i=2;i<=a;i++){
		y*=i%x;
	}
}
void count_666(int ans){
	int sum=1,cf=0;
	for(int i=1;i<=n;i++){
		if(ton[i]!=0){
			sum*=jiec(ton[i])%x;
		}
	}
	for(int i=1;i<=n-1;i++){
		if(bian[i].nfr==1&&bian[i].nto==1)continue;
		if((bian[i].nfr==1||bian[i].nto==1)&&bian[i].eeeee==false){
			cf=cf+k-1;
		}
	}
	ans=(sum+cf)%x;
	printf("%d",ans);
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cin>>c>>T;
	while(T--){
		scanf("%d%d",&n,&k);
		for(int i=1;i<=n-1;i++){
			scanf("%d%d",&bian[i].from,&bian[i].to);
			ton[bian[i].from]++;ton[bian[i].to]++;
		}
		for(int i=1;i<=k;i++){
			scanf("%d",&e[i]);
			bian[e[i]].eeeee=true;
		}
		for(int i=1;i<=n-1;i++){
			bian[i].nfr=ton[bian[i].from];
			bian[i].nto=ton[bian[i].to];
		}
		count_666(0);
	}
}
