#include<bits/stdc++.h>
// #define int long long
// #define DEBUG
#define eb emplace_back
#define mp make_pair
using namespace std;
const int P = 1e9 + 7;
using pii = pair<int, int>;
const int inf = 0x3f3f3f3f;
namespace SegmentTree{
	struct node_t{
		int l, r;
		int maxx, minn;
		#define l(x, u) tr[x][u].l
		#define r(x, u) tr[x][u].r
		#define maxx(x, u) tr[x][u].maxx
		#define minn(x, u) tr[x][u].minn
	} tr[1][2000005];
	#define lson(u) (u << 1)
	#define rson(u) (u << 1 | 1)
	int build(int u, int l, int r, int x, int *c){
		l(x, u) = l, r(x, u) = r;
		maxx(x, u) = c[l], minn(x, u) = c[l];
		if(l == r) return 0;
		int mid = (l(x, u) + r(x, u)) >> 1;
		build(lson(u), l, mid, x, c);
		build(rson(u), mid + 1, r, x, c);
		maxx(x, u) = max(maxx(x, lson(u)), maxx(x, rson(u)));
		minn(x, u) = min(minn(x, lson(u)), minn(x, rson(u)));
		return 0;
	}
	pii query(int u, int l, int r, int x){
		if(l <= l(x, u) && r >= r(x, u)) return mp(minn(x, u), maxx(x, u));
		if(l(x, u) > r || r(x, u) < l) return mp(inf, -inf);
		auto cx = query(lson(u), l, r, x);
		auto cy = query(rson(u), l, r, x);
		return mp(min(cx.first, cy.first), max(cx.second, cy.second));
	}
} using namespace SegmentTree;
namespace azus{
	int n;
	vector<int> edge[1000005];
	int dfn[1000005], rnk[1000005], toki;
	int dep[1000005];
	int g[21][500005];
	int dfs(int u, int fa){
		g[0][u] = fa;
		dep[u] = dep[fa] + 1;
		rnk[++ toki] = u;
		dfn[u] = toki;
		for(int v : edge[u]){
			if(v == fa) continue;
			dfs(v, u);
		}
		return 0;
	}
	int prework(){
		for(int i = 1; i <= 20; i ++){
			for(int j = 1; j <= n; j ++){
				g[i][j] = g[i - 1][g[i - 1][j]];
			}
		}
		return 0;
	}
	int getlca(int u, int v){
		if(dep[u] < dep[v]) swap(u, v);
		for(int i = 20; i >= 0; i --){
			if(dep[g[i][u]] >= dep[v]) u = g[i][u];
		}
		if(u == v) return v;
		for(int i = 20; i >= 0; i --){
			if(g[i][u] != g[i][v]) u = g[i][u], v = g[i][v];
		}
		return g[0][u];
	}
	int solve(int l, int r){
		auto u = query(1, l, r, 0);
		int minn = rnk[u.first], maxx = rnk[u.second];
		return dep[getlca(minn, maxx)];
	}
	int main(){
		cin >> n;
		for(int i = 1, u, v; i < n; i ++)
			cin >> u >> v, edge[u].eb(v), edge[v].eb(u);
		dfs(1, 0);
		build(1, 1, n, 0, dfn);
		prework();
		int q; cin >> q;
		while(q --){
			int l, r, k; cin >> l >> r >> k;
			int ans = 0;
			for(int i = l; i + k - 1 <= r; i ++){
				ans = max(ans, solve(i, i + k - 1));
			}
			cout << ans << "\n";
		}
		return 0;
	}
}
signed main(){
#ifndef DEBUG
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
#endif
	int T = 1;
	while(T --){
		azus::main();
	}
	return 0;
}
/*
11:52 开始写 32 分暴力把。
真的崩溃了。C 的奶龙表现，，
逆天，12:22 打完了，没经过调试就过完大衍历了
那还有半小时我能干吗
写游记吗？yy 奶龙表情包吗？
不如再想想 C 还能不能多拿点部分分把。
失败了。再想下 D 还能不能多拿点分。
大衍历跑这么快。说明随机数据下常数小
1e5 存在可能跑过去
*/