#include<bits/stdc++.h>
using namespace std;
int T,c;
int n,k,ans;
int e[500005],h[500005],ne[500005],cnt,v[500005];
int dfs(int xb){
	int sum=0;
	int bj=1;
//	cout<<xb<<endl;
	v[xb]=1;
	for(int i=h[e[xb]];i!=-1;i=ne[i]){
		if(i%2==1&&!v[i]){
			bj=0;
			sum+=dfs(i);
		}
	}
	for(int i=h[e[xb+1]];i!=-1;i=ne[i]){
		if(i%2==1&&!v[i]){
			bj=0;
			sum+=dfs(i);
		}
	}
	v[xb]=0;
	if(bj)return 1;
	return sum;
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cin>>c>>T;
	while(T--){
		ans=0;
		memset(h,-1,sizeof(h));
		memset(v,0,sizeof(v));
		cnt=0;
		cin>>n>>k;
		int x,y;
		for(int i=1;i<n;i++){
			scanf("%d%d",&x,&y);
			e[++cnt]=y;
			ne[cnt]=h[x];
			h[x]=cnt;
			e[++cnt]=x;
			ne[cnt]=h[y];
			h[y]=cnt;
		}
		int e;
		for(int i=1;i<=k;i++){
			scanf("%d",&e);
			ans+=dfs(e*2-1);
			ans=ans%1000000007;
		}
		cout<<ans<<endl;
	}
	return 0;
} 
