#include<bits/stdc++.h>
#define sf scanf
#define pf printf
#define rep(x,y,z) for(int x=y;x<=z;x++)
#define per(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
typedef long long ll;
namespace abcdefg {
	constexpr int N=6;
	typedef pair<int,int> pii;
	#define fi first 
	#define se second
	int c,t;
	int n,k;
	int u,v;
	int e;
	vector<pii> to[N];
	int ans;
	bool vi[N];
	int sum;
	pii edge[N];
	void dfs(int i) {
		++sum;
		vi[i]=1;
		if(sum==n-1) return ans++, void(0);
		int u=edge[i].fi,v=edge[i].se;
		for(auto t : to[u]) if(!vi[t.fi]) dfs(t.fi);
		for(auto t : to[v]) if(!vi[t.fi]) dfs(t.fi);
		--sum;
		vi[i]=0;
	}
	void main() {
		sf("%d%d",&c,&t);
		while(t--) {
			sf("%d%d",&n,&k);
			rep(i,1,n-1) sf("%d%d",&u,&v),edge[i]={u,v}, to[u].push_back({i,v}),to[v].push_back({i,u});
			rep(i,1,k) {
				sf("%d",&e);
				ans=0;
				dfs(e);
				pf("%d\n",ans);
			}
		}
	}
}
int main() {
	#ifdef LOCAL
	freopen("my.out","w",stdout);
	#else 
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	#endif
	abcdefg :: main();
}