#include<bits/stdc++.h>
using namespace std;const int N=5e5+5,M=N*4;bool Be;
int n,q,son[N],hs[N],tot,ans[N],mx[N];vector<int>v[N];vector<pair<int,int>>g1[N],g2[N],f1[N];vector<array<int,3>>f2[N];
void addv(int l,int r,int v){g1[l].push_back({r,v}),g2[r-l+1].push_back({l,v});}
struct node{set<array<int,3>>s;
void add(int l,int r,int v){auto it=s.lower_bound({l,r,0});
if(it!=s.end()&&(*it)[0]==r+1)addv((*it)[0],(r=(*it)[1]),(*it)[2]),it=s.erase(it);
if(it!=s.begin()&&(*--it)[1]==l-1)addv((l=(*it)[0]),(*it)[1],(*it)[2]),it=s.erase(it);
s.insert({l,r,v});
}
}*p[N];
struct sgt{int l[M],r[M],mx[M];
#define ls (k<<1)
#define rs (k<<1|1)
void build(int L=1,int R=n,int k=1){l[k]=L,r[k]=R;if(L==R)return;
int mid=L+R>>1;build(L,mid,ls),build(mid+1,R,rs);
}
void add(int u,int v,int k=1){if(u<l[k]||r[k]<u)return;
mx[k]=max(mx[k],v);if(l[k]==r[k])return;add(u,v,ls),add(u,v,rs);
}
int ask(int L,int R,int k=1){if(R<l[k]||r[k]<L)return 0;
if(L<=l[k]&&r[k]<=R)return mx[k];return max(ask(L,R,ls),ask(L,R,rs));
}
}t;
void DFS(int u,int fa){son[u]=1;for(auto i:v[u])if(i!=fa)DFS(i,u),son[u]+=son[i],son[i]>son[hs[u]]&&(hs[u]=i);}
void dfs(int u,int fa,int d){if(hs[u])dfs(hs[u],u,d+1),p[u]=p[hs[u]];else p[u]=new node;
for(auto i:v[u])if(i!=fa&&i!=hs[u]){dfs(i,u,d+1);for(auto j:p[i]->s)addv(j[0],j[1],j[2]),p[u]->add(j[0],j[1],d);}
p[u]->add(u,u,d);
}void Add(int u,int v){while(u)mx[u]=max(mx[u],v),u-=u&-u;}
int Ask(int u){int res=0;while(u<=n)res=max(res,mx[u]),u+=u&-u;return res;}
bool Ed;
int main(){freopen("query.in","r",stdin),freopen("query.out","w",stdout);
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n,t.build();for(int x,y,i=1;i<n;i++)cin>>x>>y,v[x].push_back(y),v[y].push_back(x);
DFS(1,0),dfs(1,0,1);for(auto j:p[1]->s)addv(j[0],j[1],j[2]);
cin>>q;for(int x,y,k,i=1;i<=q;i++)cin>>x>>y>>k,f1[x].push_back({k,i}),f2[k].push_back({x,y,i});
for(int i=1;i<=n;i++){for(auto j:g1[i])Add(j.first,j.second);
for(auto j:f1[i])ans[j.second]=max(ans[j.second],Ask(i+j.first-1));
}for(int i=n;i;i--){for(auto j:g2[i])t.add(j.first,j.second);
for(auto j:f2[i])ans[j[2]]=max(ans[j[2]],t.ask(j[0],j[1]-i+1));
}for(int i=1;i<=q;i++)cout<<ans[i]<<"\n";
}