#include<bits/stdc++.h>
using namespace std;
namespace traverse{
	#define N 1000010
	#define MO 1000000007
	int f[N][N],n,k;
	pair<int ,int> h[N];
	int flag[N]={0};
	long long ans=0;
	void dfs(int u,int t){
		if(t==n-1) {
			ans++;
			ans%=MO;
			return;
		}
		for(int i=1;i<=n-1;i++){
			if(flag[i]==0&&(h[u].first==h[i].first||h[u].first==h[i].second||h[u].second==h[i].first||h[u].second==h[i].second)){
				flag[i]=1;
				dfs(i,t+1);
				flag[i]=0;
			}
		}
		return;
	}
	void into(){
		ans=1;
		cin>>n>>k;
		for(int i=1;i<=n-1;i++){
			int x,y;
			scanf("%d%d",&x,&y);
			f[x][y]=i,f[y][x]=i;
			h[i]={x,y};
		}
		for(int i=1;i<=n;i++) flag[i]=0;
		for(int i=1;i<=k;i++){
			int j;
			cin>>j;
			flag[j]=1;
			dfs(j,1);
			cout<<ans<<" \n";
		}
	}
}

int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int c,_;
	scanf("%d%d",&c,&_);
	for(int i=1;i<=_;i++) traverse::into();
	return 0;
}
/*
1 1
4 1
1 2
2 3
2 4
1
*/
