#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1000000007;
int c,t,n,k,subA,cnt;
struct edge{
	int u,to,nextt;
}e[200010];
int fir[100010];
int dp[100010],u[100010],v[100010];
void add(int u,int v){
	e[++cnt].to=v,e[cnt].u=u,e[cnt].nextt=fir[u],fir[u]=cnt;
}
void dfs(int u,int father){
//	printf("%d %d\n",u,father);
	dp[u]=1;
	int sum=0;
	for(int i=fir[u];i;i=e[i].nextt){
		int v=e[i].to;
		if(v==father)continue;
		dfs(v,u);
		dp[u]*=dp[v];
		dp[u]%=mod;
		sum++;
	}
	if(sum)
		dp[u]*=sum;
	dp[u]%=mod;
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%lld%lld",&c,&t);
	while(t--){
		memset(fir,0,sizeof(fir));
		cnt=0;
		subA=0;
		scanf("%lld%lld",&n,&k);
		for(int i=1;i<n;i++){
			scanf("%lld%lld",&u[i],&v[i]);
			add(u[i],v[i]);
			add(v[i],u[i]);
			if(u[i]!=i||v[i]!=i+1)subA=1;
		}
		if(subA==0)
			printf("1\n");
		else{
			int ans=0;
			for(int i=1;i<=k;i++){
				int ee=0;
				scanf("%lld",&ee);
				for(int i=1;i<=n;i++)
					dp[i]=0;
				dfs(u[ee],v[ee]);
				dfs(v[ee],u[ee]);
				ans+=dp[u[ee]]*dp[v[ee]]%mod;
				ans%=mod;
//				printf("%lld ",dp[u[ee]]*dp[v[ee]]%mod);
			}
			printf("%lld\n",ans);
		}
	}	
	return 0;
}
