//NOIP2024 RP++
//不要挂分，不要挂分，不要挂分
//debug 深入思考，只靠样例与自己 
//没冲出来链，服了 
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long double wisdom;

const int N = 5e5 + 5;
struct Edge {int now, nxt;} e[N << 1]; int head[N], cur, deg[N];
void add(int u, int v) {e[++cur].now = v, e[cur].nxt = head[u], head[u] = cur;}
int n, m, dfn[N], idx, arr[N << 1], dep[N];
void dfs(int u, int fa) {
	dep[u] = dep[fa] + 1, arr[++idx] = dep[u], dfn[u] = idx;
	for (int i = head[u], v; i; i = e[i].nxt) if ((v = e[i].now) != fa) dfs(v, u), arr[++idx] = dep[u];
}
namespace ST {
	int lg[N], dp[20][N], mn[20][N], mx[20][N];
	void build() {
		lg[0] = -1; for (int i = 1; i <= idx; i++) lg[i] = lg[i >> 1] + 1;
		for (int i = 1; i <= idx; i++) dp[0][i] = arr[i]; for (int i = 1; i <= n; i++) mn[0][i] = mx[0][i] = dfn[i];
		for (int j = 1; j <= 19; j++) for (int i = 1; i + (1 << j) - 1 <= idx; i++) dp[j][i] = min(dp[j - 1][i], dp[j - 1][i + (1 << (j - 1))]);
		for (int j = 1; j <= 19; j++) for (int i = 1; i + (1 << j) - 1 <= n; i++) mn[j][i] = min(mn[j - 1][i], mn[j - 1][i + (1 << (j - 1))]), mx[j][i] = max(mx[j - 1][i], mx[j - 1][i + (1 << (j - 1))]);
	}
	int query(int l, int r) {
		int k = lg[r - l + 1], L = min(mn[k][l], mn[k][r - (1 << k) + 1]), R = max(mx[k][l], mx[k][r - (1 << k) + 1]);
		int t = lg[R - L + 1]; return min(dp[t][L], dp[t][R - (1 << t) + 1]);
	}
}
//namespace CHAIN {
//	int a[N];
//	bool check() {
//		int cnt = 0; for (int i = 1; i <= n; i++) if (deg[i] == 1) cnt++; else if (deg[i] != 2) return false; if (cnt != 2) return false;
//		int u = 1, fa = -1; a[1] = 1; for (int i = 2; i <= n; i++) {for (int t = head[u]; t; t = e[t].nxt) if (e[t].now != fa) {a[u = e[t].now] = i; break;}}
//		return true;
//	}
//	struct Qry {int l, r, k, id;} q[N]; int ans[N], pos[N];
//	void divide(int l, int r, int ql, int qr) {
//		if (l > r || ql > qr) return; int mid = (l + r) >> 1;
//		for (int i = )
//	}
//	void sol() {
//		for (int i = 1; i <= n; i++) pos[a[i]] = i;
//		scanf("%d", &m); for (int i = 1; i <= m; i++) scanf("%d%d%d", &q[i].l, &q[i].r, &q[i].k), q[i].id = i;
//		divide(1, n, 1, m); for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
//	}
//}
int main() {
	freopen("query.in", "r", stdin); freopen("query.out", "w", stdout);
	scanf("%d", &n);
	for (int i = 1, u, v; i < n; i++) scanf("%d%d", &u, &v), add(u, v), add(v, u), deg[u]++, deg[v]++;
	//if (CHAIN::check()) return CHAIN::sol(), 0;
	
	dfs(1, 0), ST::build(), scanf("%d", &m);
	while (m--) {
		int l, r, k, ans = 0; scanf("%d%d%d", &l, &r, &k);
		for (int i = l, j = i + k - 1; j <= r; i++, j++) ans = max(ans, ST::query(i, j));
		printf("%d\n", ans);
	}
	return 0;
}
