#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <bitset>

using namespace std;

const int maxn = 5e5 + 10;
const int lgn = 20;

int blca[maxn * 4], alca[maxn][2];
int depth[maxn], link[maxn][lgn];
int n, q;
vector<int> adj[maxn];

void initdfs(int u, int fa) {
	depth[u] = depth[fa] + 1;
	link[u][0] = fa;
	for (int i = 1; i <= lgn - 1; i++) link[u][i] = link[link[u][i - 1]][i - 1];
	for (int i = 0; i < adj[u].size(); i++) {
		int v = adj[u][i];
		if (v == fa) continue;
		initdfs(v, u);
	}
}

int lca(int a, int b) {
	if (depth[a] < depth[b]) swap(a, b);
	for (int i = lgn - 1; i >= 0; i--) {
		if (depth[link[a][i]] >= depth[b]) {
			a = link[a][i];
		}
	}
	if (a == b) return a;
	for (int i = lgn - 1; i >= 0; i--) {
		if (link[a][i] != link[b][i]) {
			a = link[a][i], b = link[b][i];
		}
	}
	return link[a][0];
}

void build(int l, int r, int x) {
	if (l == r) {
		blca[x] = alca[l][0];
		return;
	}
	if (r - l == 1) {
		blca[x] = alca[l][1];
		return;
	}
	int mid = l + (r - l) / 2;
	build(l, mid, x * 2);
	build(mid + 1, r, x * 2 + 1);
	blca[x] = max(blca[x * 2], blca[x * 2 + 1]);
}

int query(int a, int b, int l, int r, int x) {
	if (a <= l && r <= b) return blca[x];
	int mid = l + (r - l) / 2;
	int v1 = low_inf, v2 = low_inf;
	if (a <= mid) v1 = query(a, b, l, mid, x * 2);
	if (b >= mid + 1) v2 = query(a, b, mid + 1, r, x * 2 + 1);
	return max(v1, v2);
}

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	
	scanf("%d", &n);
	for (int i = 1; i <= n - 1; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	
	initdfs(1, 0);
	for (int i = 1; i <= n; i++) {
		alca[i][0] = depth[i];
	}
	for (int i = 1; i <= n - 1; i++) {
		alca[i][1] = depth[lca(i, i + 1)];
	}
	
	scanf("%d", &q);
	for (int i = 1; i <= q; i++) {
		int l, r, k;
		int ans = low_inf;
		scanf("%d%d%d", &l, &r, &k);
		for (int j = l; j <= r - l + 1; j++) {
			ans = max(ans, query(j, j + k - 1))
		}
		printf("%lld\n", ans);
	}
	
	fclose(stdin);
	fclose(stdout);
	return 0;	
}
