#include <bits/stdc++.h>
using namespace std;
const int N = 5e5, M = 18;
int n, q;
int lg[N + 5];
class graph {
	private:
	int idx;
	public:
	int head[N + 5];
	struct edge {
		int nxt, v;
	} e[(N << 1) + 5];
	void add_dir(int u, int v) {
		e[++idx] = {head[u], v};
		head[u] = idx;
	}
	void add_udir(int u, int v) {
		add_dir(u, v), add_dir(v, u);
	}
} g;
int dep[N + 5], fa[N + 5], sz[N + 5], son[N + 5], top[N + 5];
int rmq[M + 1][N + 5];
void dfs1(int u = 1) {
	dep[u] = dep[fa[u]] + 1;
	sz[u] = 1;
	for (int i = g.head[u]; i; i = g.e[i].nxt) {
		int v = g.e[i].v;
		if (v == fa[u]) continue;
		fa[v] = u;
		dfs1(v);
		sz[u] += sz[v];
		if (sz[son[u]] < sz[v]) son[u] = v;
	}
}
void dfs2(int u = 1, int tp = 1) {
	top[u] = tp;
	if (son[u]) dfs2(son[u], tp);
	for (int i = g.head[u]; i; i = g.e[i].nxt) {
		int v = g.e[i].v;
		if (v != fa[u] && v != son[u]) dfs2(v, v);
	}
}
int lca(int u, int v) {
	while (top[u] != top[v])
		dep[top[u]] > dep[top[v]] ? u = fa[top[u]] : v = fa[top[v]];
	return dep[u] < dep[v] ? u : v;
}
int query(int l, int r) {
	int k = lg[r - l + 1];
	return lca(rmq[k][l], rmq[k][r - (1 << k) + 1]);
}
int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	scanf("%d", &n);
	lg[1] = 0;
	for (int i = 2; i <= n; i++)
		lg[i] = lg[i >> 1] + 1;
	for (int _ = 1; _ < n; _++) {
		int u, v;
		scanf("%d%d", &u, &v);
		g.add_udir(u, v);
	}
	dfs1(), dfs2();
	for (int i = 1; i <= n; i++) rmq[0][i] = i;
	for (int i = 1; i <= M; i++)
		for (int j = 1; j <= n - (1 << i) + 1; j++)
			rmq[i][j] = lca(rmq[i - 1][j], rmq[i - 1][j + (1 << i - 1)]);
	scanf("%d", &q);
	for (int _ = 1; _ <= q; _++) {
		int l, r, k;
		scanf("%d%d%d", &l, &r, &k);
		int ans = 0;
		for (int i = l; i <= r - k + 1; i++)
			ans = max(ans, dep[query(i, i + k - 1)]);
		printf("%d\n", ans);
	}
	return 0;
}
