#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
list<int>edge[N];
void build(int u,int v){edge[u].push_back(v);}
int fa[N],deep[N],siz[N],son[N];
void DFS1(int u,int f)
{
    fa[u]=f;
    deep[u]=deep[f]+1;
    siz[u]=1;
    for(int v:edge[u])
    {
        if(v==f)continue;
        DFS1(v,u);
        siz[u]+=siz[v];
        if(siz[v]>siz[son[u]])son[u]=v;
    }
}
int top[N];
void DFS2(int u)
{
    if(son[fa[u]]==u)top[u]=top[fa[u]];
    else top[u]=u;
    if(son[u]!=0)DFS2(son[u]);
    for(int v:edge[u])
        if(v!=fa[u]&&v!=son[u])DFS2(v);
}
int LCA(int u,int v)
{
    while(top[u]!=top[v])
    {
        if(deep[top[u]]<deep[top[v]])swap(u,v);
        u=fa[top[u]];
    }
    if(deep[u]<deep[v])swap(u,v);
    return v;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    freopen("query.in","r",stdin);
    freopen("query.out","w",stdout);
    int n;
    cin>>n;
    for(int i=1,u,v;i<n;i++)cin>>u>>v,build(u,v),build(v,u);
    DFS1(1,0);
    DFS2(1);
    int q;
    cin>>q;
    while(q--)
    {
        int l,r,K,ans=0;
        cin>>l>>r>>K;
        for(int j=l;j+K-1<=r;j++)
        {
            int lca=j;
            for(int k=j;k<=j+K-1;k++)lca=LCA(lca,k);
            ans=max(ans,deep[lca]);
        }
        cout<<ans<<'\n';
    }
    return 0;
}
/*
#   #  #   #  ####   #####  ####   #####    #    #      #####
#   #  ##  #  #   #  #      #   #    #     # #   #      #
#   #  # # #  #   #  #####  ####     #    #   #  #      #####
#   #  #  ##  #   #  #      #  #     #    #####  #      #
 ###   #   #  ####   #####  #   #    #    #   #  #####  #####

#   #   ###     #   #     ###
#   #  #   #   # # # #   #   #
#####  #   #  #   #   #  #   #
#   #  #   #  #   #   #  #   #
#   #   ###   #   #   #   ###

  #   #    ###  #   #  ####   
 # # # #    #   ##  #  #   #
#   #   #   #   # # #  #   #
#   #   #   #   #  ##  #   #
#   #   #  ###  #   #  ####
*/