#include<bits/stdc++.h>
#define ll long long
#define N 100005
using namespace std;
int c,t,n,k,e[N];
vector<int> cpy[N],v[N];
ll ans,mod=1e9+7;
int q[N],fa[N],vis[N];
void dfs(int x){
	vis[x]++;
	int sum=0;
	for(int i=0;i<v[x].size();i++){
		if(vis[v[x][i]])continue;
		sum++;
		fa[v[x][i]]=x;
		dfs(v[x][i]);
	}
	if(sum==0){
		if(x==q[1])ans=(ans+1)%mod;
		else dfs(fa[x]);
	}
	vis[x]--;
}
void solve(){
	scanf("%d%d",&n,&k);
	for(int i=1,x,y;i<n;i++){
		scanf("%d%d",&x,&y);
		cpy[x].push_back(i);
		cpy[y].push_back(i);
	}
	for(int i=1;i<=k;i++)scanf("%d",&e[i]);
	if(n<=100){
		for(int i=1;i<=n;i++){
			for(int j=0;j<cpy[i].size();j++){
				for(int k=j+1;k<cpy[i].size();k++){
					v[cpy[i][j]].push_back(cpy[i][k]);
					v[cpy[i][k]].push_back(cpy[i][j]);
				}
			}
		}
		ans=0;
		for(int i=1;i<=k;i++){
			q[1]=e[i];
			dfs(e[i]);
		}
		printf("%lld\n",ans);
	}
	else{
		for(int i=1;i<=k;i++)printf("1\n");
	}
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%d%d",&c,&t);
	while(t--)solve();
	return 0;
}
