#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int c,T,n,k,t,ans,cnt,a[100005],b[100005],e[100005],hd[100005],to[200005],nt[200005],bz[100005];
void add(int x,int y){
	nt[++cnt]=hd[x];
	to[cnt]=y;
	hd[x]=cnt;
}
void dfs(int d){
	for(int i=hd[d];i;i=nt[i]){
		if(bz[to[i]]) continue;
		bz[to[i]]=1;
		dfs(to[i]);
		bz[to[i]]=0;
	}
	t=0;
	for(int i=1;i<n;i++)
		if(!bz[i]){
			t=1;
			break;
		}
	if(!t) ans=(ans+1)%mod;
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%d%d",&c,&T);
	while(T--){
		scanf("%d%d",&n,&k);
		for(int i=1;i<n;i++) scanf("%d%d",&a[i],&b[i]);
		ans=cnt=0;
		memset(bz,0,sizeof(bz));
		for(int i=1;i<n-1;i++)
			for(int j=i+1;j<n;j++) if(a[i]==a[j]||a[i]==b[j]||b[i]==a[j]||b[i]==b[j]) add(i,j),add(j,i);
		for(int i=1;i<=k;i++){
			scanf("%d",&e[i]);
			bz[e[i]]=1;
			dfs(e[i]);
		}
		printf("%d\n",ans);
	}
	return 0;
}
