#include <bits/stdc++.h>
#define fst first
#define snd second
using namespace std;
using ll = long long;
using ld = long double;

const long long IMX = 1ll << 30;
const long long LMX = 1ll << 60;
const int N = 500005;
int n, q;
int fa[N][21], lvl[N];
vector <int> G[N];
void dfs(int cur, int p) {
	lvl[cur] = lvl[p] + 1;
	fa[cur][0] = p;
	for (int i = 1; i <= 20; i++) fa[cur][i] = fa[fa[cur][i - 1]][i - 1];
	for (auto v : G[cur]) {
		if (v == p) continue;
		dfs(v, cur);
	}
}
int LCA(int u, int v) {
	if (lvl[u] < lvl[v]) swap(u, v);
	for (int i = 20; i >= 0; i--) {
		if ((lvl[u] - lvl[v] >> i) & 1) u = fa[u][i];
	}
	if (u == v) return u;
	for (int i = 20; i >= 0; i--) {
		if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
	}
	return fa[u][0];
}
int main() {
	ios :: sync_with_stdio(0);
	cin.tie(nullptr);
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1, 0);
	cin >> q;
	while (q--) {
		int l, r, k, ans = 0;
		cin >> l >> r >> k;
		for (int i = l; i + k - 1 <= r; i++) {
			int lca = i;
			for (int j = i + 1; j <= i + k - 1; j++) lca = LCA(lca, j);
			ans = max(ans, lvl[lca]);
		}
		cout << ans << '\n';
	}
	return 0;
}

