#include <bits/stdc++.h>
using namespace std;
const int N = 524288, M = N << 1;
int d[N], a[N];
vector<int> e[N];
void Dfs(int x, int z)
{
	d[x] = d[z] + 1;
	for (int y : e[x])
		if (y != z)
			Dfs(y, x);
}
int main()
{
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	for (int i = 1; i < n; ++i)
	{
		int x, y;
		cin >> x >> y;
		e[x].push_back(y);
		e[y].push_back(x);
	}
	d[0] = 0;
	Dfs(1, 0);
	int q;
	cin >> q;
	while (q-- != 0)
	{
		int l, r, k, m;
		cin >> l >> r >> k;
		m = r - l + 1;
		copy(d + l, d + r + 1, a + 1);
		sort(a + 1, a + m + 1, [&](int x, int y) { return x > y;});
		cout << a[k] << '\n';
	}
	return 0;
}
