#include<bits/stdc++.h>
#define coin const int
#define ull unsigned long long
#define ll long long
// #define int ll

using namespace std;
const int N = 500000 + 10;
const int inf = 998244353;

int read () {
	int x = 0, k = 1; char c = 0;
	while (c < '0' || c > '9') { if (c == '-') k = -1; c = getchar(); }
	while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ '0'), c = getchar();
	return x * k;
}

int n, q;
int l, r, k;
int u, v, ret;
vector<int> G[N];

int M = 23, fa[N][32], dep[N];
void dfs (int u, int p) {
	fa[u][0] = p, dep[u] = dep[p] + 1;
	for (int i = 1; i <= M; ++i) fa[u][i] = fa[fa[u][i - 1]][i - 1];
	for (int v: G[u]) if (v != p) dfs(v, u);
}

inline int lca (int a, int b) {
	if (!a || !b) return a ^ b;
	if (dep[a] < dep[b]) swap(a, b); int c = dep[a] - dep[b];
	for (int i = M; i >= 0; --i) if (c & (1 << i)) a = fa[a][i];
	if (a == b) return a;
	for (int i = M; i >= 0; --i) if (fa[a][i] != fa[b][i]) a = fa[a][i], b = fa[b][i];
	return fa[a][0];
}
/*
namespace Solu1 {
	#define ls (o << 1)
	#define rs (o << 1 | 1)
	#define mid ((l + r) >> 1)
	
	int val[N << 2];
	inline void build (int o, int l, int r) {
		if (l == r) return val[o] = l, void();
		build(ls, l, mid), build(rs, mid + 1, r);
		val[o] = lca(val[ls], val[rs]);
	}

	inline int query (int o, int L, int R, int l, int r) {
		if (L <= l && r <= R) return val[o]; int ret = 0;
		if (L <= mid) ret = lca(ret, query(ls, L, R, l, mid));
		if (mid < R) ret = lca(ret, query(rs, L, R, mid + 1, r));
		return ret;
	}
} 
*/
namespace Solu2 {
	int rVal[N][32], lVal[N][32];
	inline void build (int o, int l, int r) {
		for (int i = 1; i <= n; ++i) rVal[i][0] = lVal[i][0] = i;
		for (int k = 1; k <= M; ++k) for (int i = n; i >= 1; --i) if (i + (1 << (k - 1)) <= n) rVal[i][k] = lca(rVal[i][k - 1], rVal[i + (1 << (k - 1))][k - 1]);
		for (int k = 1; k <= M; ++k) for (int i = 1; i <= n; ++i) if (i - (1 << (k - 1)) >= 1) lVal[i][k] = lca(lVal[i][k - 1], lVal[i - (1 << (k - 1))][k - 1]);
	}

	inline int query (int o, int L, int R, int l, int r) {
		int k = __lg(R - L + 1);
		return lca(rVal[L][k], lVal[R][k]);
	}
}

using namespace Solu2;

signed main () {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);

	n = read();
	for (int i = 1; i < n; ++i) u = read(), v = read(), G[u].push_back(v), G[v].push_back(u);
	dfs(1, 0), build(1, 1, n), q = read();
	for (int i = 1; i <= q; ++i) {
		l = read(), r = read(), k = read(), ret = 0;
		while (l + k - 1 <= r) ret = max(ret, dep[query(1, l, l + k - 1, 1, n)]), ++l;
		printf("%d\n", ret);
	}
	return 0;
}

/*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3

*/

