// I love Furina forever
# include <bits/stdc++.h>
# define maxn 500100
# define mod 1000000007
# define mem(a, val) memset(a, val, sizeof(a))
# define rep(i, j, k) for(int i = j; i <= k; ++i)
# define per(i, j, k) for(int i = j; i >= k; --i)
# define go(i, u) for(int i = head[u], v = to[i]; i; i = nxt[i], v = to[i])
using namespace std;

int n, q;
int head[maxn], to[maxn << 1], nxt[maxn << 1], tot;
int dep[maxn], deg[maxn], dfn[maxn], Maxdeg;

inline void add_edge(int u, int v) {nxt[++tot] = head[u]; to[tot] = v; head[u] = tot; deg[u]++;}

namespace Subtask1 {
	int d[maxn << 2], stp, ccnt;
	int st[maxn * 3][22], Max[maxn][20], Min[maxn][20], Log[maxn];
	
	inline void init() {
		rep(i, 1, n) Max[i][0] = dfn[i], Min[i][0] = dfn[i]; rep(i, 1, stp) st[i][0] = d[i];
		rep(i, 1, 20) rep(l, 1, n - (1 << i) + 1) Max[l][i] = max(Max[l][i - 1], Max[l + (1 << i - 1)][i - 1]), Min[l][i] = min(Min[l][i - 1], Min[l + (1 << i - 1)][i - 1]);
		rep(i, 1, 21) rep(l, 1, stp - (1 << i) + 1) st[l][i] = min(st[l][i - 1], st[l + (1 << i - 1)][i - 1]);
		rep(i, 0, 20) rep(j, (1 << i), min(500000, (1 << i + 1) - 1)) Log[j] = i;
	}
	
	inline void dfs(int u, int fat) {dep[u] = dep[fat] + 1; dfn[u] = ++stp; d[stp] = dep[u]; go(i, u) if(v != fat) dfs(v, u), d[++stp] = dep[u];}
	inline int queryMax(int l, int r) {int len = Log[r - l + 1]; return max(Max[l][len], Max[r - (1 << len) + 1][len]);}
	inline int queryMin(int l, int r) {int len = Log[r - l + 1]; return min(Min[l][len], Min[r - (1 << len) + 1][len]);}
	inline int query(int l, int r) {int len = Log[r - l + 1]; return min(st[l][len], st[r - (1 << len) + 1][len]);}
	
	inline void solve() {
		dfs(1, 1); init(); cin >> q;
		while(q--) {
			int i, j, k, ll, rr, ans = 0; cin >> i >> j >> k;
			for(int l = i, r = i + k - 1; r <= j; l++, r++) {ll = queryMin(l, r), rr = queryMax(l, r); ans = max(ans, query(ll, rr)); ++ccnt;}
			cout << ans << '\n';
		}
	}
}

namespace Subtask2 {
}

signed main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	rep(i, 2, n) {int u, v; cin >> u >> v; add_edge(u, v); add_edge(v, u);}
	Subtask1::solve();
	return 0;
}

