#include<bits/stdc++.h>
using I=int;using str=std::string;
template<class T>using V=std::vector<T>;
template<class T,I N>using A=std::array<T,N>;
void solve(){
  I n;std::cin>>n;V<V<I>>g(n+1);
  for(I i=1;i<=n-1;i++){
    I u,v;std::cin>>u>>v;
    g[u].push_back(v);g[v].push_back(u);
  }

  V<I>fa(n+1),dep(n+1),sz(n+1),son(n+1);
  auto dfs1=[&](auto&&dfs1,I u,I p)->void{
    fa[u]=p;dep[u]=dep[p]+1;sz[u]=1;
    for(I v:g[u])if(v!=p){
      dfs1(dfs1,v,u);
      sz[u]+=sz[v];
      if(sz[v]>sz[son[u]])son[u]=v;
    }
  };
  dfs1(dfs1,1,0);
  V<I>top(n+1),dfn(n+1),rev(n+1);I cnt=0;
  auto dfs2=[&](auto&&dfs2,I u,I p)->void{
    top[u]=p;dfn[u]=++cnt;rev[cnt]=u;
    if(son[u])dfs2(dfs2,son[u],p);
    for(I v:g[u])if(v!=fa[u]&&v!=son[u])dfs2(dfs2,v,v);
  };
  dfs2(dfs2,1,1);
  
  auto lca=[&](I u,I v){
    for(;top[u]!=top[v];u=fa[top[u]])
      if(dep[top[u]]<dep[top[v]])std::swap(u,v);
    return dep[u]<dep[v]?u:v;
  };
  
  A<V<I>,21>fmin,fmax;for(I i=0;i<=20;i++)fmin[i]=fmax[i]=V<I>(n+1);
  for(I i=1;i<=n;i++)fmin[0][i]=fmax[0][i]=dfn[i];
  for(I j=1;j<=20;j++)for(I i=1;i+(1<<j)-1<=n;i++){
    fmin[j][i]=std::min(fmin[j-1][i],fmin[j-1][i+(1<<(j-1))]);
    fmax[j][i]=std::max(fmax[j-1][i],fmax[j-1][i+(1<<(j-1))]);
  }
  auto qrmin=[&](I l,I r){
    I k=std::__lg(r-l+1);
    return std::min(fmin[k][l],fmin[k][r-(1<<k)+1]);
  };
  auto qrmax=[&](I l,I r){
    I k=std::__lg(r-l+1);
    return std::max(fmax[k][l],fmax[k][r-(1<<k)+1]);
  };
  
  auto lca2=[&](I l,I r){
    return lca(rev[qrmin(l,r)],rev[qrmax(l,r)]);
  };

  I q;std::cin>>q;
  while(q--){
    I l,r,k;std::cin>>l>>r>>k;
    I w=0;
    for(I i=l;i+k-1<=r;i++)w=std::max(w,dep[lca2(i,i+k-1)]);
    std::cout<<w<<'\n';
  }
}
#define fio(a,b) freopen("query."#a,#b,std##a)
int main(){
  fio(in,r);fio(out,w);
  std::cin.tie(0)->sync_with_stdio(0);
  //int t;std::cin>>t;while(t--)
  solve();
  return 0;
}
