#include<bits/stdc++.h>
using namespace std;
int n,m,dfn[500005],d,minn[500005][20],lg[500005],dep[500005],st[500005][20];
vector<int>e[500005];
void dfs(int pos,int fa,vector<int>e[]){
  dep[pos]=dep[fa]+1,minn[dfn[pos]=++d][0]=fa;
  for(int i=0;i<e[pos].size();i++)if(e[pos][i]!=fa)dfs(e[pos][i],pos,e);
}
int cmp(int a,int b){
  return dfn[a]<dfn[b]?a:b;
}
void init(int s,vector<int>e[]){
  dfs(s,0,e);
  for(int i=2;i<=d;i++)lg[i]=lg[i>>1]+1;
  for(int j=1;1<<j<=d;j++)for(int i=1;i+(1<<j)-1<=d;i++)minn[i][j]=cmp(minn[i][j-1],minn[i+(1<<(j-1))][j-1]);
}
int lca(int u,int v){
  if(u==v)return u;
  u=dfn[u],v=dfn[v];
  if(u>v)swap(u,v);
  return u++,cmp(minn[u][lg[v-u+1]],minn[v-(1<<lg[v-u+1])+1][lg[v-u+1]]);
}
int query(int l,int r){
  return lca(st[l][lg[r-l+1]],st[r-(1<<lg[r-l+1])+1][lg[r-l+1]]);
}
int main(){
  freopen("query.in","r",stdin);
  freopen("query.out","w",stdout);
  ios::sync_with_stdio(0),cin.tie(0),cin>>n;
  for(int i=1,u,v;i<n;i++)cin>>u>>v,e[u].push_back(v),e[v].push_back(u);
  init(1,e);
  for(int i=1;i<=n;i++)st[i][0]=i;
  for(int j=1;1<<j<=n;j++)for(int i=1;i+(1<<j)-1<=n;i++)st[i][j]=lca(st[i][j-1],st[i+(1<<(j-1))][j-1]);
  cin>>m;
  for(int i=1,l,r,k;i<=m;i++){
    cin>>l>>r>>k;
    int ans=0;
    for(int j=l;j<=r-k+1;j++)ans=max(ans,dep[query(j,j+k-1)]);
    cout<<ans<<'\n';
  }
  return 0;
}
