#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int N = 1e5 + 10;
int C , T , n , u , v , q , l , r , k;
int main()
{
	freopen("query.in" , "r" , stdin);
	freopen("query.out" , "w" , stdout);
	cin >> n;
	for(int i = 1 ; i < n ; i ++)
	{
		cin >> u >> v; 
	}
	cin >> q;
	for(int i = 1 ; i <= q ; i ++)
	{
		cin >> l >> r >> k;
		cout << rand() << endl;
	}
	return 0;
}

