#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
int dep[N];
vector<int> bi[N];
int main()
{
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	int n;
	cin >> n;
	for(int i = 1; i < n; i++)
	{
		int x, y;
		cin >> x >> y;
		bi[x].push_back(y);
		bi[y].push_back(x);
	}
	dep[1] = 1;
	int t = 1;
	for(int i = 2; i <= n; i++)
	{
		if(dep[bi[t][0]])
			t = bi[t][1];
		else
			t = bi[t][0];
		dep[t] = i;
	}
	int q;
	cin >> q;
	while(q--)
	{
		int l, r, k;
		cin >> l >> r >> k;
		k--;
		int ma = 0;
		for(int i = l; i <= r - k; i++)
		{
			int mi = n + 10;
			for(int j = i; j <= i + k; j++)
				mi = min(mi, dep[j]);
			ma = max(ma, mi);
		}
		cout << ma << endl;
	}
	return 0;
}
