#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int maxn = 500000;
struct edge{
	int to, nxt;
}e[maxn * 2 + 10];
int h[maxn + 10], idx;
void add_edge(int u, int v) {
	e[++idx].to = v;
	e[idx].nxt = h[u];
	h[u] = idx;
}
int n, q;
int l, r, k;
int dep[maxn + 10];
void dfs(int u, int fa) {
	for (int i = h[u]; i; i = e[i].nxt) {
		int v = e[i].to;
		if (v == fa) continue;
		dep[v] = dep[u] + 1;
		dfs(v, u);
	}
}
int st[maxn + 10][30];
int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i < n; ++i) {
		int u, v;
		cin >> u >> v;
		add_edge(u, v);
		add_edge(v, u);
	}
	dep[1] = 1;
	dfs(1, 0);
	for (int i = 1; i <= n; ++i) st[i][0] = dep[i];
	for (int j = 1; j <= 20; ++j)
		for (int i = 1; i + (1 << j) - 1 <= n; ++i)
			st[i][j] = min(st[i][j-1], st[i + (1 << (j - 1))][j-1]); 
	cin >> q;
	int ans = 0, kk;
	while (q--) {
		ans = 1;
		cin >> l >> r >> k;
		kk = log2(k);
		for (int i = l, j = l + k - 1; j <= r; ++i, ++j) {
			ans = max(ans, min(st[i][kk], st[j - (1 << kk) + 1][kk]));
		}
		cout << ans << '\n';
	}
	return 0;
}

