#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, k, q, fa[N][30], dep[N], lca[N][30];
struct Edge {
	int to, nxt;
} e[2 * N];
int head[N], cnt;
void add(int u, int v) {
	e[++cnt].to = v;
	e[cnt].nxt = head[u];
	head[u] = cnt;
}
bool vis[N];
void dfs(int u, int d) {
	vis[u] = true;
	dep[u] = d;
	int v;
	for (int i = head[u]; i; i = e[i].nxt) {
		v = e[i].to;
		if (vis[v]) continue;
		fa[v][0] = u;
		dfs(v, d + 1);
	}
}
int query(int x, int y) {
	if (dep[x] < dep[y]) swap(x, y);
	for (int i = k; i >= 0; i--)
		if (dep[fa[x][i]] >= dep[y])
			x = fa[x][i];
	if (x == y) return x;
	for (int i = k; i >= 0; i--)
		if (fa[x][i] != fa[y][i])
			x = fa[x][i], y = fa[y][i];
	return fa[x][0];
}
int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	scanf("%d", &n);
	k = log2(n);
	int u, v;
	for (int i = 1; i < n; i++) {
		scanf("%d%d", &u, &v);
		add(u, v); add(v, u);
	}
	dfs(1, 1);
	for (int j = 1; j <= k; j++)
		for (int i = 1; i <= n; i++)
			fa[i][j] = fa[fa[i][j-1]][j-1];
	for (int i = 1; i <= n; i++) lca[i][0] = i;
	for (int j = 1; j <= k; j++)
		for (int i = 1; i <= n; i++) {
			if (i+(1<<j)-1 > n) break;
			lca[i][j] = query(lca[i][j-1], lca[i+(1<<(j-1))][j-1]);
		}
	scanf("%d", &q);
	int l, r, len;
	for (int w = 1; w <= q; w++) {
		scanf("%d%d%d", &l, &r, &len);
		int mx = 0, kk = log2(len);
		for (int i = l; i + len - 1 <= r; i++) {
			mx = max(mx, dep[query(lca[i][kk], lca[i+len-(1<<kk)][kk])]);
		}
		printf("%d\n", mx);
	}
	return 0;
}
