#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;

const int N = 5e5 + 5;

int n, q;
vector<int> g[N];

int tr[N << 2];

int f[N][20];
int dep[N][20];

int deg[N];

void dfs(int u, int fa) {
	dep[u][0] = dep[fa][0] + 1;
	f[u][0] = fa;
	for (int i = 1; i <= 19; i++)
		f[u][i] = f[f[u][i - 1]][i - 1];
	for (auto v: g[u]) {
		if (v == fa) continue;
		dfs(v, u);
	}
}
int lca(int x, int y) {
	if (!x || !y) return x + y;
	if (dep[x][0] < dep[y][0]) swap(x, y);
	for (int i = 19; i >= 0; i--)
		if (dep[f[x][i]][0] >= dep[y][0])
			x = f[x][i];
	if (x == y) return x;
	for (int i = 19; i >= 0; i--)
		if (f[x][i] != f[y][i])
			x = f[x][i], y = f[y][i];
	return f[x][0];
}

void build(int p, int l, int r) {
	if (l == r) {
		tr[p] = l;
		return;
	}
	int mid = l + r >> 1;
	build(p << 1, l, mid);
	build(p << 1 | 1, mid + 1, r);
	tr[p] = lca(tr[p << 1], tr[p << 1 | 1]);
}
int query(int p, int l, int r, int L, int R) {
	if (l > R || r < L) return 0;
	if (L <= l && r <= R) return tr[p];
	int mid = l + r >> 1;
	return lca(query(p << 1, l, mid, L, R), query(p << 1 | 1, mid + 1, r, L, R));
}

bool chain() {
	int cnt = 0;
	for (int i = 1; i <= n; i++)
		if (deg[i] == 1) cnt++;
	return cnt <= 2;
}

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n;
	for (int i = 1, u, v; i < n; i++) {
		cin >> u >> v;
		g[u].emplace_back(v);
		g[v].emplace_back(u);
		deg[u]++, deg[v]++;
	}
	
	dfs(1, 0);
	
	if (chain()) {
		for (int j = 1; (1 << j) <= n; j++)
			for (int i = 1; i + (1 << j) - 1 <= n; i++)
				dep[i][j] = max(dep[i][j - 1], dep[i + (1 << j - 1)][j - 1]);
		cin >> q;
		while (q--) {
			int l, r, k;
			cin >> l >> r >> k;
			k = __lg(r - l + 1);
			cout << max(dep[l][k], dep[r - (1 << k) + 1][k]) << "\n";
		}
		return 0;
	}
	build(1, 1, n);
	
	cin >> q;
	while (q--) {
		int l, r, k;
		cin >> l >> r >> k;
		int ans = 0;
		for (int i = l; i <= r - k + 1; i++) {
			ans = max(ans, dep[query(1, 1, n, i, i + k - 1)][0]);
//			printf("lca[%d, %d] is %d\n", i, i + k - 1, query(1, 1, n, i, i + k - 1));
		}
		cout << ans << "\n";
	}
	
	return 0;
}
/*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3
*/
