#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5;
const int maxm=20;
int n,m;
vector<int> E[maxn+5];
int de[maxn+5];
int fa[maxn+5][maxm+5];
int res[maxn+5][maxm+5];
int lg[maxn+5];
void Dfs(int u){
    de[u]=de[fa[u][0]]+1;
    for(int i=1;i<=maxm;i++)
        fa[u][i]=fa[fa[u][i-1]][i-1];
    for(int v:E[u]){
        if(v==fa[u][0]) continue;
        fa[v][0]=u;
        Dfs(v);
    }
}
inline int Lca(int u,int v){
    if(de[u]<de[v]) swap(u,v);
    for(int i=maxm;i>=0;i--)
        if(de[fa[u][i]]>=de[v])
            u=fa[u][i];
    if(u==v) return u;
    for(int i=maxm;i>=0;i--)
        if(fa[u][i]!=fa[v][i])
            u=fa[u][i],v=fa[v][i];
    return fa[u][0];
}
inline int Query(int l,int r){
    int k=lg[r-l+1];
    return Lca(res[l][k],res[r-(1<<k)+1][k]);
}
signed main(){
    freopen("query.in","r",stdin);
    // freopen("query2.in","r",stdin);
    freopen("query.out","w",stdout);
    int u,v;
    scanf("%d",&n);
    for(int i=2;i<=n;i++)
        lg[i]=lg[i>>1]+1;
    for(int i=1;i<n;i++){
        scanf("%d%d",&u,&v);
        E[u].emplace_back(v);
        E[v].emplace_back(u);
    }
    Dfs(1);
    for(int i=1;i<=n;i++)
        res[i][0]=i;
    for(int j=1;j<=maxm;j++)
        for(int i=1;i<=n;i++)
            res[i][j]=Lca(res[i][j-1],res[min(n,i+(1<<(j-1)))][j-1]);
    int l,r,K;
    scanf("%d",&m);
    while(m--){
        v=0;
        scanf("%d%d%d",&l,&r,&K);
        for(int i=l;i+K-1<=r;i++)
            v=max(v,de[Query(i,i+K-1)]);
        printf("%d\n",v);
    }
    return 0;
}