#include <bits/stdc++.h>
#define fi first
#define se second
#define MP make_pair
using namespace std;

const int N = 5e5 + 7;

vector<int> e[N];
int st1[22][N], st2[22][N];
int n, q, mi[22][N], dfn[N], dep[N], dn;

int shx(int x, int y) { return dfn[x] < dfn[y] ? x : y; }
int yzx(int x, int y) { return dfn[x] > dfn[y] ? x : y; }
void dfs(int x, int pre) {
	dep[x] = dep[pre] + 1;
	mi[0][dfn[x] = ++ dn] = pre;
	for (int i : e[x])
		if (i != pre) dfs(i, x);
}
void init() {
	for (int i = 1; i <= n; i ++)
		st1[0][i] = st2[0][i] = i;
	for (int i = 1; i <= __lg(n); i ++)
		for (int j = 1; j + (1 << i) - 1 <= n; j ++) {
			mi[i][j] = shx(mi[i - 1][j], mi[i - 1][j + (1 << i - 1)]);
			st1[i][j] = shx(st1[i - 1][j], st1[i - 1][j + (1 << i - 1)]);
			st2[i][j] = yzx(st2[i - 1][j], st2[i - 1][j + (1 << i - 1)]);
		}
}
int LCA(int u, int v) {
	if (u == v) return u;
	if ((u = dfn[u]) > (v = dfn[v])) swap(u, v);
	int d = __lg(v - ++ u);
	return shx(mi[d][u], mi[d][v - (1 << d) + 1]);
}
int lzy(int l, int r) {
	int d = __lg(r - l + 1);
	int u = shx(st1[d][l], st1[d][r - (1 << d) + 1]);
	int v = yzx(st2[d][l], st2[d][r - (1 << d) + 1]);
	return dep[LCA(u, v)];
}

signed main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	ios::sync_with_stdio(0); 
	cin >> n;
	for (int i = 1, u, v; i < n; i ++) {
		cin >> u >> v;
		e[u].push_back(v), e[v].push_back(u);
	}
	cin >> q;
	dfs(1, 0), init();
	for (int i = 1, l, r, k; i <= q; i ++) {
		cin >> l >> r >> k;
		int ans = 0;
		for (int j = l; j <= r - k + 1; j ++)
			ans = max(ans, lzy(j, j + k - 1));
		cout << ans << '\n';
	}
	return 0;
}
 
