#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
vector<int> p[maxn];
int dp[maxn][23];
int dep[maxn];
void dfs(int u,int fa) {
dp[u][0] = fa;
for(int i = 0;i < p[u].size();i++) {
int v = p[u][i];
if(v == fa) continue;
dep[v] = dep[u] + 1;
dfs(v,u);
}
}
int get_lca(int x,int y) {
if(dep[x] < dep[y]) {
swap(x,y);
}
for(int i = 20;i >= 0;i--) {
if(dep[dp[x][i]] >= dep[y]) {
x = dp[x][i];
}
}
if(x == y) return x;
for(int i = 20;i >= 0;i--) {
if(dp[x][i] != dp[y][i]) {
x = dp[x][i];
y = dp[y][i];
}
}
return dp[x][0];
}
int tree[maxn * 4];
void build(int u,int l,int r) {
if(l == r) {
tree[u] = l;
return ;
}
int mid = (l + r) >> 1;
build(u << 1,l,mid);
build(u << 1 | 1,mid + 1,r);
tree[u] = get_lca(tree[u << 1],tree[u << 1 | 1]);
}
int query(int u,int l,int r,int l1,int r1) {
if(l1 <= l && r <= r1) {
return tree[u];
}
int mid = (l + r) >> 1;
if(r1 <= mid) return query(u << 1,l,mid,l1,r1);
else if(l1 > mid) return query(u << 1 | 1,mid + 1,r,l1,r1);
else return get_lca(query(u << 1,l,mid,l1,r1),query(u << 1 | 1,mid + 1,r,l1,r1));
}
signed main() {
freopen("query.in","r",stdin);
freopen("query.out","w",stdout);
int n;
cin>>n;
int x,y,z;
for(int i = 1;i < n;i++) {
cin>>x>>y;
p[x].push_back(y);
p[y].push_back(x);
}
dep[1] = 1;
dfs(1,1);
for(int j = 1;j <= 20;j++) {
for(int i = 1;i <= n;i++) {
dp[i][j] = dp[dp[i][j - 1]][j - 1];
}
}
build(1,1,n);
int q;
cin>>q;
for(int i = 1;i <= q;i++) {
cin>>x>>y>>z;
int ans = 0;
for(int l = x;l + z - 1 <= y;l++) {
int r = l + z - 1;
ans = max(ans,dep[query(1,1,n,l,r)]);
}
cout<<ans<<endl;
}
return 0;
}