#include <bits/stdc++.h>

using namespace std;

const int N = 5000;

struct edge {
	int nxt, to;
} e[N + 5];
int n, tot, head[N + 5], a[2 * N + 5], cnt, dep[N + 5], f[2 * N + 5][20], b[N + 5], lca[N + 5][N + 5], ans;

void add(int u, int v) {
	e[++tot] = {head[u], v};
	head[u] = tot;
}

void dfs(int x, int fthr) {
	a[++cnt] = x;
	b[x] = cnt;
	dep[x] = dep[fthr] + 1;
	for (int i = head[x]; i; i = e[i].nxt) {
		if (e[i].to == fthr) continue;
		dfs(e[i].to, x);
		a[++cnt] = x;
	}
} 

int Lca(int x, int y) {
	if (x == y) return x;
	if (b[x] > b[y]) swap(x, y);
	int k = log2(b[y] - b[x] + 1);
	return min(f[b[x]][k], f[b[y] - (1 << k) + 1][k]);
}

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		int u, v; scanf("%d%d", &u, &v);
		add(u, v);
		add(v, u);
	}
	dfs(1, 0);
	for (int i = 1; i <= cnt; i++)
		f[i][0] = dep[a[i]];
	for (int i = 1; i <= 19; i++) {
		for (int j = 1; j + (1 << i) - 1 <= cnt; j++) {
			if (f[j][i - 1] < f[j + (1 << i - 1)][i - 1]) f[j][i] = f[j][i - 1];
			else f[j][i] = f[j + (1 << i - 1)][i - 1];
		}
	}
	for (int i = 1; i <= n; i++) {
		lca[i][i] = i;
		for (int j = i + 1; j <= n; j++)
			lca[i][j] = Lca(lca[i][j - 1], j);
	}
	int q; scanf("%d", &q);
	while (q--) {
		int l, r, k;
		scanf("%d%d%d", &l, &r, &k);
		ans = 0;
		for (int i = l; i + k - 1 <= r; i++)
			ans = max(ans, lca[i][i + k - 1]);
		printf("%d\n", ans);
	}
}
