#include<cstdio>
#include<cctype>
#include<vector>
using namespace std;
template<typename _Tp>
inline void read(_Tp& x){
    static char ch;
    while(ch=getchar(),!isdigit(ch));
    x=(ch^48);
    while(ch=getchar(),isdigit(ch))x=(x<<3)+(x<<1)+(ch^48);
}
template<typename _Tp,typename ..._Args>
inline void read(_Tp& x,_Args &...args){
    read(x);
    read(args...);
}
const int N=5e5+10;
int n,q,dep[N],mndfn[21][N],mxdfn[21][N],mndep[21][N<<1],idx,dfn[N<<1],fst[N],sht_lg2[N<<1];
vector<int> road[N];
void dfs(int x){
    dfn[++idx]=x;
    fst[x]=idx;
    for(auto& i:road[x]){
        if(fst[i])continue;
        dep[i]=dep[x]+1;
        dfs(i);
        dfn[++idx]=x;
    }
}
int query(int l,int r){
    int tlg=sht_lg2[r-l+1];
    int tmn=min(mndfn[tlg][l],mndfn[tlg][r-(1<<tlg)+1]);
    int tmx=max(mxdfn[tlg][l],mxdfn[tlg][r-(1<<tlg)+1]);
    tlg=sht_lg2[tmx-tmn+1];
    return min(mndep[tlg][tmn],mndep[tlg][tmx-(1<<tlg)+1]);
}
int main(){
    freopen("query.in","r",stdin);
    freopen("query.out","w",stdout);
    read(n);
    for(int i=1,x,y;i<n;i++){
        read(x,y);
        road[x].emplace_back(y);
        road[y].emplace_back(x);
    }
    sht_lg2[0]=-1;
    dep[1]=1;
    dfs(1);
    for(int i=1;i<=idx;i++){
        sht_lg2[i]=sht_lg2[i>>1]+1;
        mndep[0][i]=dep[dfn[i]];
        // printf("%d%c",mndep[0][i]," \n"[i==idx]);
    }
    for(int i=1;i<=n;i++){
        mxdfn[0][i]=mndfn[0][i]=fst[i];
    }
    for(int i=0;i<sht_lg2[idx];i++){
        for(int j=1;j+(1<<(i+1))-1<=idx;j++){
            mndep[i+1][j]=min(mndep[i][j],mndep[i][j+(1<<i)]);
        }
    }
    for(int i=0;i<sht_lg2[n];i++){
        for(int j=1;j+(1<<(i+1))-1<=n;j++){
            mxdfn[i+1][j]=max(mxdfn[i][j],mxdfn[i][j+(1<<i)]);
            mndfn[i+1][j]=min(mndfn[i][j],mndfn[i][j+(1<<i)]);
        }
    }
    read(q);
    for(int i=1,l=0,r=0,k=0,res=0;i<=q;i++){
        read(l,r,k);
        res=0;
        for(int j=l;j+k-1<=r;j++){
            res=max(res,query(j,j+k-1));
        }
        printf("%d\n",res);
    }
}
/*
10:03 brute implementation (Sparse Table) finished. 32 points?
10:26 took 12 min to find out an critical bug lol now really 32 points
11:48 found something bizarre and modified it
*/