#include<bits/stdc++.h>
#define N 500001
using namespace std;
int n,q;
bool flag=true;
vector<int>g[N];
int lg[N];
int dep[N];
int fa[N][21];
int lc[21][N];
void dfs(int u,int f){
    dep[u]=dep[f]+1;
    fa[u][0]=f;
    for(int i=1;i<=20;i++){
        fa[u][i]=fa[fa[u][i-1]][i-1];
    }
    for(int v:g[u]){
        if(v==f)continue;
        dfs(v,u);
    }
}
int lca(int u,int v){
    if(dep[u]<dep[v])swap(u,v);
    for(int i=20;i>=0;i--){
        if(dep[fa[u][i]]>=dep[v])u=fa[u][i];
    }
    if(u==v)return u;
    for(int i=20;i>=0;i--){
        if(fa[u][i]!=fa[v][i]){
            u=fa[u][i];
            v=fa[v][i];
        }
    }
    return fa[u][0];
}
inline void build(){
    for(int i=1;i<=n;i++){
        lc[0][i]=i;
    }
    for(int i=1;i<=20;i++){
        for(int j=1;j+(1<<i)-1<=n;j++){
            lc[i][j]=lca(lc[i-1][j],lc[i-1][j+(1<<(i-1))]);
        }
    }
}
inline int lcs(int l,int r){
    int tmp=lg[r-l+1];
    return lca(lc[tmp][l],lc[tmp][r-(1<<tmp)+1]);
}
int main(){
    freopen("query.in","r",stdin);
    freopen("query.out","w",stdout);
    scanf("%d",&n);
    lg[0]=-1;
    for(int i=1;i<=n;i++){
        lg[i]=lg[i/2]+1;
    }
    for(int i=1;i<n;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1,0);
    build();
    scanf("%d",&q);
    while(q--){
        int res=0;
        int l,r,k;
        scanf("%d%d%d",&l,&r,&k);
        for(int i=l;i+k-1<=r;i++){
            res=max(res,dep[lcs(i,i+k-1)]);
        }
        printf("%d\n",res);
    }
}
