#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 5, M = 2e5 + 5, INF = 1e18, mod = 1e9 + 7;

int C, n, k, U[N], V[N], ans;
bool t[N];
vector <int> g[N];

/*
以关键边作为起始边，有多少种不同的生成树

*/

void solve()
{
	cin >> n >> k;
	for (int i = 1, u, v; i < n; i++)
		cin >> u >> v, g[u].push_back(v), g[v].push_back(u), U[i] = u, V[i] = v;
	srand(time(0));
	for (int i = 1, x; i <= k; i++)
	{
		cin >> x;
		cout << rand() << endl;
	}
}

void init()
{
	ans = 0;
	for (int i = 1; i <= n; i++)
		g[i].clear(), U[i] = V[i] = t[i] = 0;
}

signed main()
{
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	int Test; cin >> C >> Test;
	while (Test--)
		init(), solve();
	
	
	return 0;
}
