#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long n, q;
vector<int> G[N];
int dep[N], f[N][20]; 
void dfs(int u, int fa){
	for(int v: G[u]){
		if(v == fa) continue;
		f[v][0] = u; dep[v] = dep[u] + 1;
		for(int i=1; 1<<i<=dep[v]; i++)
			f[v][i] = f[f[v][i-1]][i-1];
		dfs(v, u);
	}
}
int lca(int x, int y){
	if(dep[x] < dep[y]) swap(x, y);
	if(y == 0) return x;
	for(int i=19; i>=0; i--)
		if(dep[f[x][i]] >= dep[y]) 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];
}
struct Seg_Tree{
	struct Node{int l, r, dat;} t[N<<2];
	#define ls (u << 1)
	#define rs (u << 1 | 1) 
	void build(int u, int l, int r){
		t[u].l = l, t[u].r = r;
		if(l == r){t[u].dat = l;return;}
		int mid = (l + r) >> 1;
		build(ls, l, mid);
		build(rs, mid+1, r);
		t[u].dat = lca(t[ls].dat, t[rs].dat);
	}
	int query(int u, int l, int r){
		if(l <= t[u].l && t[u].r <= r) return t[u].dat;
		int mid = (t[u].l + t[u].r) >> 1, res = 0;
		if(l <= mid) res = lca(res, query(ls, l, r));
		if(r > mid) res = lca(res, query(rs, l, r));
		return res;
	}
}t;
signed main(){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	cin.tie(nullptr) -> sync_with_stdio(false);
	cin >> n;
	for(int i=1; i<n; i++){
		int u, v; cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dep[1] = 1; dfs(1, 0);
	t.build(1, 1, n);
	for(cin >> q; q --> 0;){
		int l, r, k; cin >> l >> r >> k;
		int ans = 0;
		for(int i=l+k-1; i<=r; i++){
			ans = max(ans, dep[t.query(1, i-k+1, i)]);
		}
		cout << ans << "\n";
	}
	return 0;
}
