#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
char buf[1<<23],*p1=buf,*p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?EOF:*p1++)
template<class rd>
void read(rd &x){
char c=getchar();
for(;c<48||c>57;c=getchar());
for(x=0;c>47&&c<58;c=getchar())x=(x<<1)+(x<<3)+(c^48);
}
int n,m,dp[N],fa[N],tp[N],son[N],sz[N],lp[N],rp[N],ans[N];
vector<int>e[N],g[N],lk[N];
bool vis[N];
struct node{
int l,r,w;
}q[N];
vector<node>va[N];
set<pair<int,int> >s[N];
#define L k<<1
#define R k<<1|1
struct seg{
int tr[N<<2];
void upd(int k,int l,int r,int x,int v){
tr[k]=max(tr[k],v);
if(l==r)return vis[l]=true,void();
int mid=l+r>>1;
if(x<=mid)upd(L,l,mid,x,v);
else upd(R,mid+1,r,x,v);
}
int query(int k,int l,int r,int x,int y){
if(tr[k]<y)return -1;
if(l==r)return l;
int mid=l+r>>1,o=-1;
if(x>mid)o=query(R,mid+1,r,x,y);
if(o==-1)o=query(L,l,mid,x,y);
return o;
}
}T;
struct seg2{
int tr[N<<2],tg[N<<2];
void pushtg(int k,int v){
tg[k]=max(tg[k],v);
tr[k]=max(tr[k],v);
}
void pushdown(int k){
if(tg[k]){
pushtg(L,tg[k]);
pushtg(R,tg[k]);
tg[k]=0;
}
}
void upd(int k,int l,int r,int x,int y,int v){
if(x<=l&&r<=y)return pushtg(k,v);
int mid=l+r>>1;
pushdown(k);
if(x<=mid)upd(L,l,mid,x,y,v);
if(y>mid)upd(R,mid+1,r,x,y,v);
tr[k]=max(tr[L],tr[R]);
}
int query(int k,int l,int r,int x,int y){
if(x<=l&&r<=y)return tr[k];
int mid=l+r>>1,res=0;
pushdown(k);
if(x<=mid)res=max(res,query(L,l,mid,x,y));
if(y>mid)res=max(res,query(R,mid+1,r,x,y));
return res;
}
}T2;
void dfs1(int x){
sz[x]=1;
for(auto v:e[x])if(!sz[v]){
fa[v]=x,dp[v]=dp[x]+1;
dfs1(v);
sz[x]+=sz[v];
if(sz[v]>sz[son[x]])son[x]=v;
}
}
void dfs2(int x,int t){
tp[x]=t;
if(son[x])dfs2(son[x],t);
for(auto v:e[x])if(!tp[v])dfs2(v,v);
}
int lca(int x,int y){
for(int fx=tp[x],fy=tp[y];fx!=fy;x=fa[fx],fx=tp[x])if(dp[fx]<dp[fy])swap(x,y),swap(fx,fy);
return dp[x]<dp[y]?x:y;
}
int gr(int x){
return rp[x]==x?x:rp[x]=gr(rp[x]);
}
int main(){
freopen("query.in","r",stdin);
freopen("query.out","w",stdout);
read(n);
for(int i=1,x,y;i<n;++i){
read(x),read(y);
e[x].emplace_back(y);
e[y].emplace_back(x);
}
dp[1]=1,dfs1(1),dfs2(1,1);
read(m);
for(int i=1;i<=m;++i){
read(q[i].l),read(q[i].r),read(q[i].w);
g[q[i].w].emplace_back(i);
}
for(int i=1;i<n;++i){
int u=lca(i,i+1);
lk[dp[u]].emplace_back(i);
}
for(int i=1;i<=n;++i){
lp[i]=rp[i]=i;
va[1].push_back(node{lp[i],rp[i],dp[i]});
}
for(int i=n;i;--i){
for(auto v:lk[i]){
int o=gr(v+1);
rp[v]=o,lp[o]=lp[v];
va[o-lp[o]+1].push_back(node{lp[o],o,i});
}
}
for(int i=n;i;--i){
for(auto v:va[i]){
s[v.l].insert(make_pair(v.r,v.w));
if(!vis[v.l])T.upd(1,1,n,v.l,v.r);
T2.upd(1,1,n,v.l,v.r,v.w);
}
for(auto v:g[i]){
int ql=q[v].r-i+1,qr=q[v].l+i-1;
int u=T.query(1,1,n,ql,qr);
auto it=s[u].lower_bound(make_pair(qr,-1));
ans[v]=it->second;
if(ql>qr)ans[v]=max(ans[v],T2.query(1,1,n,qr,ql));
}
}
for(int i=1;i<=m;++i)printf("%d\n",ans[i]);
return 0;
}