#include<bits/stdc++.h>
#define fo(i,x,y) for(int i(x);i<=y;i=-~i)
#define fd(i,x,y) for(int i(x);i>=y;--i)
#define ll long long
#define pb push_back
using namespace std;
char ST;

const int N=5e5+5;

int n,q,dfn[N],dep[N],fa[N],mat[N],sz,p[25],lo[N],st[N][21],mn[N][21],mx[N][21],ans;
vector<int>e[N];
struct qry{
    int l,r,k;
}b[N];

int read(){
    char ch(getchar());int nu(0),o(0);
    while(ch<48||ch>57){
        if(ch=='-')o=1;ch=getchar();
    }
    while(ch>=48&&ch<=57){
        nu=(nu<<1)+(nu<<3)+(ch^48);ch=getchar();
    }
    if(o)nu=-nu;
    return nu;
}
void write(int x){
    if(x>9)write(x/10);putchar(x%10^48);
}

void dfs(int x,int pa){
    fa[x]=pa;dep[x]=dep[pa]+1;dfn[x]=++sz;mat[sz]=x;
    for(auto y:e[x]){
        if(y==pa)continue;
        dfs(y,x);
    }
}
int rmq_st(int l,int r){
    int t(lo[r-l+1]);
    return dep[st[l][t]]<dep[st[r-p[t]+1][t]]?st[l][t]:st[r-p[t]+1][t];
}
int rmq_mn(int l,int r){
    int t(lo[r-l+1]);
    return dfn[mn[l][t]]<dfn[mn[r-p[t]+1][t]]?mn[l][t]:mn[r-p[t]+1][t];
}
int rmq_mx(int l,int r){
    int t(lo[r-l+1]);
    return dfn[mx[l][t]]>dfn[mx[r-p[t]+1][t]]?mx[l][t]:mx[r-p[t]+1][t];
}
int lca(int x,int y){
    if(dfn[x]>dfn[y])swap(x,y);
    return x==y?x:fa[rmq_st(dfn[x]+1,dfn[y])];
}
void init(){
    lo[1]=0;fo(i,2,n)lo[i]=lo[i>>1]+1;
    p[0]=1;fo(i,1,20)p[i]=p[i-1]<<1;
    fo(i,1,n)st[i][0]=mat[i];
    fo(i,1,n)mn[i][0]=mx[i][0]=i;
    fo(j,1,lo[n])fo(i,1,n-p[j]+1)st[i][j]=dep[st[i][j-1]]<dep[st[i+p[j-1]][j-1]]?st[i][j-1]:st[i+p[j-1]][j-1];
    fo(j,1,lo[n])fo(i,1,n-p[j]+1)mn[i][j]=dfn[mn[i][j-1]]<dfn[mn[i+p[j-1]][j-1]]?mn[i][j-1]:mn[i+p[j-1]][j-1];
    fo(j,1,lo[n])fo(i,1,n-p[j]+1)mx[i][j]=dfn[mx[i][j-1]]>dfn[mx[i+p[j-1]][j-1]]?mx[i][j-1]:mx[i+p[j-1]][j-1];
}

namespace task1{
    void solve(){
        fo(i,1,q){
            int L(b[i].l),R(b[i].r),k(b[i].k);
            ans=0;
            fo(l,L,R-k+1){
                int r(l+k-1),u(rmq_mn(l,r)),v(rmq_mx(l,r)),lc(lca(u,v));
                ans=max(ans,dep[lc]);
            }
            write(ans);putchar(10);
        }
    }
}

void solve(){
    task1::solve();
}

char EN;
int main(){
    freopen("query.in","r",stdin);freopen("query.out","w",stdout);
    // cerr<<(&EN-&ST)/1048576.0<<'\n';
    n=read();
    fo(i,1,n-1){
        int x(read()),y(read());
        e[x].pb(y);e[y].pb(x);
    }
    q=read();
    fo(i,1,q)b[i]=(qry){read(),read(),read()};
    dfs(1,0);
    init();
    solve();
    return 0;
}
