#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pb push_back
#define fi first
#define sc second
using namespace std;
typedef pair<int,int> pii;
typedef long long LL;
bool _ST;
template<typename T>
void read(T &x){
x=0;char c=getchar();
while(c<'0'||c>'9') c=getchar();
while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c&15);c=getchar();}
}
const int N=5e5+100;
int n,q,siz[N],dep[N],son[N],pos[N],idx,ans[N],maxx[N];
vector<int> E[N],node[N];
struct QUE{int l,r,k,id;};
vector<QUE> qu1[N];
vector<pii> opt1[N],opt2[N],qu2[N];
struct LIST{
int fa[N],ls[N],rs[N];
bool vis[N];
void init(){
rep(i,1,n) ls[i]=i,rs[i]=i,fa[i]=i,vis[i]=0;
}
int getf(int x){return x==fa[x]?x:fa[x]=getf(fa[x]);}
void merge(int x,int y){
x=getf(x),y=getf(y);
if(x==y) return;
fa[y]=x,ls[x]=min(ls[x],ls[y]),rs[x]=max(rs[x],rs[y]);
}
void insert(int x,int di){
vis[x]=1,ls[x]=rs[x]=x;
if(vis[x-1]) merge(x,x-1);
if(vis[x+1]) merge(x,x+1);
int rr=rs[getf(x)],ll=ls[getf(x)];
opt1[rr-ll+1].pb({ll,di});
opt2[ll].pb({rr,di});
}
void del(int x){
vis[x]=0,ls[x]=rs[x]=fa[x]=x;
}
}TR;
void dfs1(int x,int ff){
dep[x]=dep[ff]+1,siz[x]=1;
for(auto y:E[x]) if(y!=ff){
dfs1(y,x);
siz[x]+=siz[y];
if(siz[y]>siz[son[x]]) son[x]=y;
}
}
void dfs2(int x,int ff){
for(auto y:E[x]) if(y!=son[x]&&y!=ff){
dfs2(y,x);
for(auto i:node[pos[y]]) TR.del(i);
}
if(son[x]) dfs2(son[x],x);
pos[x]=son[x]?pos[son[x]]:++idx;
TR.insert(x,dep[x]),node[pos[x]].pb(x);
for(auto y:E[x]) if(y!=son[x]&&y!=ff){
for(auto i:node[pos[y]]) {
TR.insert(i,dep[x]),node[pos[x]].pb(i);
}
node[pos[y]].clear(),node[pos[y]].shrink_to_fit();
}
}
int mx[N<<2];
#define ls(x) x<<1
#define rs(x) x<<1|1
void update(int x,int l,int r,int u){
if(l==r) return mx[x]=maxx[l],void();
int mid=l+r>>1;
(mid>=u)?update(ls(x),l,mid,u):update(rs(x),mid+1,r,u);
mx[x]=max(mx[ls(x)],mx[rs(x)]);
}
int query(int x,int l,int r,int L,int R){
if(L<=l&&r<=R) return mx[x];
int mid=l+r>>1,res=0;
if(mid>=L) res=query(ls(x),l,mid,L,R);
if(mid<R) res=max(res,query(rs(x),mid+1,r,L,R));
return res;
}
namespace sub1{
int dfn[N],Ti,mi[20][N],pos[N],lc[20][N];
void dfs1(int x,int ff){
pos[dfn[x]=++Ti]=x,mi[0][dfn[x]]=ff;
dep[x]=dep[ff]+1;
for(auto y:E[x]) if(y!=ff) dfs1(y,x);
}
int gmin(int x,int y){return dfn[x]<dfn[y]?x:y;}
void ST_build(){
rep(t,1,__lg(n)) rep(i,1,n-(1<<t)+1) mi[t][i]=gmin(mi[t-1][i],mi[t-1][i+(1<<t-1)]);
}
int LCA(int x,int y){
if(x==y) return x;
if((x=dfn[x])>(y=dfn[y])) swap(x,y);
int k=__lg(y-x++);
return gmin(mi[k][x],mi[k][y-(1<<k)+1]);
}
void solve(){
dfs1(1,0),ST_build();
rep(i,1,n) lc[0][i]=i;
rep(t,1,__lg(n)) rep(i,1,n-(1<<t)+1) lc[t][i]=LCA(lc[t-1][i],lc[t-1][i+(1<<t-1)]);
auto query=[&](int l,int r){
int k=__lg(r-l+1);
return LCA(lc[k][l],lc[k][r-(1<<k)+1]);
};
rep(i,1,n) for(auto p:qu1[i]){
int l=p.l,r=p.r,k=p.k,id=p.id;
ans[id]=dep[query(l,r)];
}
rep(i,1,q) printf("%d\n",ans[i]);
}
}
signed main(){
freopen("query.in","r",stdin);
freopen("query.out","w",stdout);
read(n);
rep(i,1,n-1){
int u,v;read(u),read(v);
E[u].pb(v),E[v].pb(u);
}
bool FL=1;
read(q);
rep(i,1,q){
int l,r,k;read(l),read(r),read(k);
if(r-l+1!=k) FL=0;
qu1[k].pb((QUE){l,r,k,i});
qu2[l].pb({l+k-1,i});
}
if(FL) return sub1::solve(),0;
TR.init();
dfs1(1,0),dfs2(1,0);
per(i,n,1){
for(auto p:opt1[i]){
int l=p.fi,di=p.sc;
if(maxx[l]<di) maxx[l]=di,update(1,1,n,l);
}
for(auto p:qu1[i]){
int l=p.l,r=p.r,k=p.k,id=p.id;
ans[id]=query(1,1,n,l,r-k+1);
}
}
rep(i,1,n) maxx[i]=0;
rep(i,1,n*4) mx[i]=0;
rep(i,1,n){
for(auto p:opt2[i]){
int r=p.fi,di=p.sc;
if(maxx[r]<di) maxx[r]=di,update(1,1,n,r);
}
for(auto p:qu2[i]){
int r=p.fi,id=p.sc;
ans[id]=max(ans[id],query(1,1,n,r,n));
}
}
rep(i,1,q) printf("%d\n",ans[i]);
bool _ED;
fprintf(stderr,"%.6lf MB\n",1.0*(&_ST-&_ED)/1024.0/1024.0);
fprintf(stderr,"%.6lf s\n",1.0*clock()/CLOCKS_PER_SEC);
return 0;
}