#include <bits/stdc++.h>
#define ls k << 1
#define rs k << 1 | 1
using namespace std;
const int N = 5e5 + 10, Log = 20, INF = 10000;
int dfn[N], tim, f[N][Log], dep[N];
vector<int> G[N];
void dfs (int u, int faa) {
	dep[u] = dep[faa] + 1;
	f[u][0] = faa;
	for (int i = 1; i < Log; i++)
		f[u][i] = f[f[u][i - 1]][i - 1];
	dfn[u] = ++tim;
	for (int i = 0; i < G[u].size(); i++) {
		int v = G[u][i];
		if (v == faa) continue;
		dfs (v, u);
	}
}
inline int lca (int x, int y) {
	if (dep[x] < dep[y]) swap(x, y);
	for (int i = Log - 1; i >= 0; i--)
		if (dep[f[x][i]] >= dep[y]) x = f[x][i];
	if (x == y) return y;
	for (int i = Log - 1; i >= 0; i--)
		if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
	return f[x][0];
}
int v[N][2];
struct pos {
	int l, r, k, ind, ans;
}p[N];
inline bool cmp (pos a, pos b) {
	return a.k < b.k;
}
inline bool cmp1 (pos a, pos b) {
	return a.ind < b.ind;
}
struct node {	
	int l, r, mx;
}tr[N * 4];
inline int max (int a, int b) {return a > b ? a : b;}
inline void update (int k) {
	tr[k].mx = max(tr[ls].mx, tr[rs].mx);
}
inline void build (int k, int l, int r) {
	tr[k].l = l, tr[k].r = r;
	if (l == r) return;
	int mid = (l + r) >> 1;
	build(ls, l, mid);
	build(rs, mid + 1, r);
}
inline void change (int k, int pos, int val) {
	if (tr[k].l == tr[k].r) {
		tr[k].mx = val;
		return;
	}
	int mid = (tr[k].l + tr[k].r) >> 1;
	if (pos <= mid) change (ls, pos, val);
	else change (rs, pos, val);
	update(k);
}
inline int query (int k, int l, int r) {
	if (l <= tr[k].l && tr[k].r <= r) 
		return tr[k].mx;
	int mid = (tr[k].l + tr[k].r) >> 1, res = -INF;
	if (l <= mid) res = max(res, query(ls, l, r));
	if (mid < r) res = max(res, query(rs, l, r));
	return res;
}
int nowv[N];
int cg[N], top;
signed main () {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	int n;
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dfs (1, 0);
	for (int i = 1; i <= n; i++) v[i][0] = v[i][1] = i, nowv[i] = i, cg[i] = i;
	top = n;
	int q, nowk = 0;
	scanf("%d", &q);
	for (int i = 1; i <= q; i++) 
		scanf("%d%d%d", &p[i].l, &p[i].r, &p[i].k), p[i].ind = i, p[i].k --;
	sort (p + 1, p + 1 + q, cmp);
	build (1, 1, n);
	for (int i = 1; i <= n; i++) change(1, i, dep[i]);
	for (int i = 1; i <= q; i++) {
		while (nowk < p[i].k) {
			nowk ++;
			for (int j = 1; j <= top; j++) {
				if (cg[j] <= nowk) {swap(cg[j], cg[top]); top--; j--; continue;}
				if (dfn[v[cg[j] - nowk][0]] <= dfn[cg[j]] && dfn[cg[j]] <= dfn[v[cg[j] - nowk][1]]) {swap(cg[j], cg[top]); top--; j--; continue;}
				if (dfn[v[cg[j] - nowk][0]] > dfn[cg[j]]) v[cg[j] - nowk][0] = cg[j];
				if (dfn[v[cg[j] - nowk][1]] < dfn[cg[j]]) v[cg[j] - nowk][1] = cg[j];
				nowv[cg[j] - nowk] = lca(nowv[cg[j] - nowk], cg[j]);
				change(1, cg[j] - nowk, dep[nowv[cg[j] - nowk]]);
			}
		}
		p[i].ans = query(1, p[i].l, p[i].r - nowk);
	}
	sort (p + 1, p + 1 + q, cmp1);
	for (int i = 1; i <= q; i++) printf("%d\n", p[i].ans);
	return 0;
}
