#include <iostream>
#include <vector>

#define endl '\n'

using namespace std;

int n, q, l, r, k, maxdep, lg[500009], f[500009][20], dep[500009], dp[500009][20];
vector<int> g[500009];

void dfs(int u, int fa) {
	dep[u] = dep[fa] + 1;
	maxdep = max(maxdep, dep[u]);
	f[u][0] = fa;
	for (int v: g[u]) {
		if (v != fa) {
			dfs(v, u);
		}
	}
}

int lca(int u, int v) {
	if (u == v) {
		return u;
	}
	if (dep[u] < dep[v]) {
		swap(u, v);
	}
	for (int i = 19; i >= 0; i--) {
		if (dep[f[u][i]] >= dep[v]) {
			u = f[u][i];
		}
	}
	for (int i = 19; i >= 0; i--) {
		if (f[u][i] != f[v][i]) {
			u = f[u][i];
			v = f[v][i];
		}
	}
	return u != v ? f[u][0] : u;
}

inline int get(int l, int r) {
	int Lg = lg[r - l + 1];
//	cout << l << " " << r  << " " << r - (1 << Lg) + 1 << " " << Lg << " " << dp[l][Lg] << " " << dp[r - (1 << Lg) + 1][Lg] << " " << lca(dp[l][Lg], dp[r - (1 << Lg) + 1][Lg]) << endl;
	return dep[lca(dp[l][Lg], dp[r - (1 << Lg) + 1][Lg])];
}

signed main() {
	freopen("query.in", "rt", stdin);
	freopen("query.out", "wt", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin >> n;
	for (int i = 1, u, v; i < n; i++) {
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1, 0);
	lg[0] = -1;
	for (int i = 1; i <= n; i++) {
		lg[i] = lg[i >> 1] + 1;
	}
	for (int i = 1; i <= 19; i++) {
		for (int j = 1; j <= n; j++) {
			f[j][i] = f[f[j][i - 1]][i - 1];
		}
	}
	for (int i = 1; i < n; i++) {
		dp[i][0] = i;
	}
	for (int i = 1; (1 << i - 1) <= n; i++) {
		for (int j = 1; j + (1 << i - 1) <= n; j++) {
			dp[j][i] = lca(dp[j][i - 1], dp[j + (1 << i - 1)][i - 1]);
		}
	}
//	for (int i = 1; i <= n; i++) {
//		for (int j = i + 1; j <= n; j++) {
//			cout << i << " " << j << " " << lca(i, j) << endl;
//		}
//	}
	cin >> q;
	for (int i = 1; i <= q; i++) {
		cin >> l >> r >> k;
		int res = -1;
		for (int L = l; L + k - 1 <= r; L++) {
			res = max(res, get(L, L + k - 1));
		}
		cout << res << endl;
	}
}
