#include <bits/stdc++.h>
using namespace std;
int c, t, n, k, u[100005], v[100005], e[100005], ans, hv[100005];
struct point{
	int u, v;
}p[100005];
vector<int> edge[100005], vis[100005];
void dfs(int now){
	hv[now] = 1;
	for (int i = 0; i < edge[now].size(); ++i){
		if (!hv[edge[now][i]]){
			dfs(edge[now][i]);
		}
		
	}
	return;
}
int main(){
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout); 
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> c >> t;
	while(t--){
		memset(hv, 0, sizeof(hv));
		cin >> n >> k;
		for (int i = 1; i < n; ++i){
			cin >> p[i].u >> p[i].v;
			for (int j = 0; j < vis[p[i].u].size(); ++j){
				edge[vis[p[i].u][j]].push_back(i);
				edge[i].push_back(vis[p[i].u][j]);
			}
			for (int j = 0; j < vis[p[i].v].size(); ++j){
				edge[vis[p[i].v][j]].push_back(i);
				edge[i].push_back(vis[p[i].v][j]);
			}
			vis[p[i].u].push_back(i);
			vis[p[i].v].push_back(i);
		}
		for (int i = 1; i <= k; ++i){
			cin >> e[i];
			dfs(e[i]);
		}
		cout << 2 << endl;
	}
	return 0;
}
