#include<bits/stdc++.h>
#define inf 100000000000
#define lnt long long
using namespace std;
int xx;char ff,chh;inline int read(){
    xx=ff=0;while(!isdigit(chh)){if(chh=='-'){ff=1;}chh=getchar();}
    while(isdigit(chh)){xx=(xx<<1)+(xx<<3)+chh-'0';chh=getchar();}return ff? -xx: xx;
}
const lnt N=2e5,MOD=1e9+7;
void sr_init(){freopen("query.in","r",stdin);freopen("query.out","w",stdout);}
int son[N],top[N],siz[N],lca[N],dep[N],fa[N];
int n,lg[N];
int st[N][20];
vector<int> G[N];
void dfs1(int,int);
void dfs2(int,int,int);
int LCA(int a,int b);
int gans(int l,int r){
    int len=r-l+1,lgg=lg[len];
    return LCA(st[l][lgg],st[r-(1<<lgg)+1][lgg]);
}
bool checkA();
struct qs{int l,r,id;}date[N];
struct tray{
    #define lowbit(x) ((-x)&(x))
    int g[N];void update(int b,int k){while(b<N){g[b]+=k;b+=lowbit(b);}}
    int query(int b){int tp=0;while(b){tp+=g[b];b-=lowbit(b);}return tp;}
}t;
int main(){
    sr_init();
    n=read();
    for(int i=1;i<n;++i){
        int x=read(),y=read();
        G[x].push_back(y);
        G[y].push_back(x);
    }
    dfs1(1,0);
    dfs2(1,1,0);
//    if(checkA()){
//        int G=read();
//        for(int i=0;i<G;++i){date[i].l=read();date[i].r=read();date[i].id=i;}
//        sort(date,date+G,[](qs x,qs y){return x.l==y.l? x.r<y.r: x.l<y.l;});
//        int now=0;
//        for(int l=1;l<=n;){
//            while(date[now].l<l){++now;}
//            while(l<date[now]){++l;}
//
//        }
//    }
    for(int i=2;i<=n;++i){lg[i]=lg[i>>1]+1;}
    for(int i=1;i<=n;++i){st[i][0]=i;}
    for(int e=1;e<=lg[n]+1;++e){
        int ls=1<<(e-1);
        for(int i=1;i<=n;++i){
            if(st[i][e-1]==0 || st[i+ls][e-1]==0){continue;}
            st[i][e]=LCA(st[i][e-1],st[i+ls][e-1]);
            //printf("%d %d %d\n",i,i+(1<<e)-1,st[i][e]);
        }
    }
    int G=read();
    while(G--){
        int l=read(),r=read(),k=read();
        int ans=0;
        for(int i=l;i+k-1<=r;++i){
            //int anst=i;
            //for(int e=i;e<=i+k-1;++e){anst=LCA(anst,e);}
            int anst=gans(i,i+k-1);
            if(dep[anst]>dep[ans]){ans=anst;}
        }
        printf("%d\n",dep[ans]);
    }

    return 0;
}
int LCA(int a,int b){
    while(top[a]!=top[b]){
        if(dep[top[a]]<dep[top[b]]){b=fa[top[b]];}
        else{a=fa[top[a]];}
    }
    return dep[a]<dep[b]? a: b;
}
void dfs1(int u,int _fa){
    fa[u]=_fa;dep[u]=dep[_fa]+1;siz[u]=1;
    for(auto to: G[u]){
        if(to==_fa){continue;}
        dfs1(to,u);
        if(siz[son[u]]<siz[to]){son[u]=to;}
        siz[u]+=siz[to];
    }
}
void dfs2(int u,int tp,int _fa){
    top[u]=tp;
    if(son[u]==0){return;}
    dfs2(son[u],tp,u);
    for(auto to: G[u]){
        if(to==_fa || to==son[u]){continue;}
        dfs2(to,to,u);
    }
}
bool checkA(){
    for(int i=1;i<=n;++i){if(top[i]!=1){return 0;}}
    return 1;
}
