#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
#define fi first
#define se second
using namespace std; using pii = pair<int,int>;
const int N=5e5+5;
int n,Q; vector<int> to[N];
namespace Solve1{
    int dep[N],dfn[N],ded[N],raw[N],dfscnt,fa[N]; pii mn[16][5005]; int mnd[16][5005],mxd[16][5005];
    void dfs(int u,int pa){
        fa[u]=pa; dep[u]=dep[pa]+1; raw[dfn[u]=++dfscnt]=u;
        for(int v:to[u]) if(v!=pa) dfs(v,u);
        ded[u]=dfscnt;
    }
    int lca(int u,int v){
        if(u==v) return u;
        int l=dfn[u],r=dfn[v]; if(l>r) swap(l,r);
        l++; int k=__lg(r-l+1); return fa[min(mn[k][l],mn[k][r-(1<<k)+1]).se];
    }
    int work(int l,int r){
        int k=__lg(r-l+1); int u=raw[min(mnd[k][l],mnd[k][r-(1<<k)+1])], v=raw[max(mxd[k][l],mxd[k][r-(1<<k)+1])];
        return dep[lca(u,v)];
    }
    [[noreturn]] void Mian(){
        dfs(1,0); For(u,1,n) mn[0][dfn[u]]=pii(dep[u],u);
        For(k,1,15) For(i,1,n-(1<<k)+1) mn[k][i]=min(mn[k-1][i],mn[k-1][i+(1<<(k-1))]);
        For(i,1,n) mnd[0][i]=mxd[0][i]=dfn[i];
        For(k,1,15) For(i,1,n-(1<<k)+1){
            mnd[k][i]=min(mnd[k-1][i],mnd[k-1][i+(1<<(k-1))]);
            mxd[k][i]=max(mxd[k-1][i],mxd[k-1][i+(1<<(k-1))]);
        }
        while(Q--){
            int l,r,k; cin>>l>>r>>k;
            int ans=0; For(i,l,r-k+1) ans=max(ans,work(i,i+k-1));
            cout<<ans<<'\n';
        }
        exit(0);
    }
}
int main(){
    Fin("query.in"); Fout("query.out");
    cin>>n; For(i,1,n-1) { int x,y; cin>>x>>y; to[x].push_back(y); to[y].push_back(x); }
    cin>>Q;
    if(n<=5000&&Q<=5000) Solve1::Mian();
    return 0;
}