#include <bits/stdc++.H>
using namespace std;

const int N = 5e5 + 10;
int n, q, dep[N], tmp[N];
vector<int> e[N];

void dfs(int u, int f)
{
	dep[u] = dep[f] + 1;
	for (int v : e[u]) if (v != f) dfs(v, u);
}

int main()
{
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for (int i = 1, u, v; i < n; ++i)
	{
		cin >> u >> v;
		e[u].emplace_back(v);
		e[v].emplace_back(u);
	}
	dfs(1, 0);
	cin >> q;
	while (q--)
	{
		int l, r, k;
		cin >> l >> r >> k;
		for (int i = l; i <= r; ++i) tmp[i] = dep[i];
		sort(tmp + l, tmp + r + 1);
		cout << tmp[r - k + 1] << '\n';
	}
	return 0;
}
/*
6
5 6
6 1
6 2
2 3
2 4
*/
