#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
int n;
vector<int> edge[N];

int st[20][N], dep[N], fa[N], top[N], son[N], siz[N];

inline int lca(int a, int b) {
	while (top[a] != top[b]) {
		if (dep[top[a]] < dep[top[b]])
			swap(a, b);
		a = fa[top[a]];
	}
	if (dep[a] > dep[b])
		return b;
	return a;
}

inline int query(int l, int r) {
	int s = __lg(r - l + 1);
	return lca(st[s][l], st[s][r - (1 << s) + 1]);
}

inline void dfs(int u, int f) {
	dep[u] = dep[f] + 1;
	fa[u] = f;
	siz[u] = 1;
	for (int v : edge[u]) {
		if (v == f)
			continue;
		dfs(v, u);
		siz[u] += siz[v];
		if (siz[v] > siz[son[u]])
			son[u] = v;
	}
}

inline void dfs2(int u, int t) {
	top[u] = t;
	if (son[u])
		dfs2(son[u], t);
	for (int v : edge[u]) {
		if (v == fa[u] || v == son[u])
			continue;
		dfs2(v, v);
	}
}

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int i = 1, u, v; i < n; i++) {
		cin >> u >> v;
		edge[u].emplace_back(v);
		edge[v].emplace_back(u);
	}
	dfs(1, 0);
	fa[1] = 1;
	dfs2(1, 1);
	for (int i = 1; i <= n; i++)
		st[0][i] = i;
	for (int j = 1; j < 20; j++)
		for (int i = 1; i + (1 << j) - 1 <= n; i++)
			st[j][i] = lca(st[j - 1][i], st[j - 1][i + (1 << j - 1)]);

	// for (int j = 1; j < 20; j++)
	// 	for (int i = 1; i + (1 << j) - 1 <= n; i++)
	// 		cout << st[j][i] << " \n"[i + (1 << j) - 1 == n];
	int q;
	cin >> q;
	while (q--) {
		int l, r, k;
		cin >> l >> r >> k;
		int ans = 0;
		for (int i = l + k - 1; i <= r; i++)
			ans = max(ans, dep[query(i - k + 1, i)]);
		cout << ans << '\n';
	}
}
