#include<iostream>
#include<string.h>
#include<map>
using namespace std;
#define N 100010
#define M 1000000007
#define LL long long
LL T,C,k,n,h[N],b,c,o,ans;
bool t[N];
struct s{
	LL a,b,l;
};s a[N*2];
void cun(int x,int y){
	a[++k].a=x,a[k].b=y;
	a[k].l=h[x],h[x]=k;
}
void dfs(int w,int l){
	bool ok=1;
	for(int i=h[w];i;i=a[i].l){
		if(t[a[i].b]) continue;
		ok=0;
		t[a[i].b]=1;
		dfs(a[i].b,l+1);
		t[a[i].b]=0;
	}
	if(ok&&l>=2){
		ans=(ans+1)%M;
	}
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%d%d",&C,&T);
	while(T--){
		scanf("%lld%lld",&n,&o);
		k=0,ans=0;
		memset(h,0,sizeof(h));
		for(int i=1;i<=n-1;i++){
			scanf("%d%d",&c,&b);
			cun(c,b);
			cun(b,c);
		}
		for(int i=1;i<=o;i++){
			scanf("%d",&c);
			t[c]=1;
			dfs(c,0);
			t[c]=0;
		}
		printf("%lld\n",ans);
	}
	return 0;
}
