#include<bits/stdc++.h>
using namespace std;
int read(){
int x=0;char c=getchar();
while(c<'0'||c>'9')c=getchar();
while(c>='0'&&c<='9')x=x*10+(c^'0'),c=getchar();
return x;
}
int n,m;
vector<int> edge[500005];
int fa[500005],dep[500005],siz[500005],son[500005],top[500005];
int val[500005],st[500005],tp;
struct node{
int l,r,x;
bool operator <(const node &b)const{return r-l<b.r-b.l;}
}a[1000005];int len;
struct Query{
int l,r,x,id;
bool operator <(const Query &b)const{return x<b.x;};
}que[500005];
int ans[500005];
void dfs1(int x,int f){
fa[x]=f,dep[x]=dep[f]+1,siz[x]=1;
for(int y:edge[x])if(y!=f){
dfs1(y,x);
siz[x]+=siz[y];
if(siz[y]>siz[son[x]])son[x]=y;
}
}
void dfs2(int x,int t){
top[x]=t;
if(son[x])dfs2(son[x],t);
for(int y:edge[x])if(y!=fa[x]&&y!=son[x])dfs2(y,y);
}
int LCA(int x,int y){
while(top[x]!=top[y])
if(dep[top[x]]>=dep[top[y]])x=fa[top[x]];
else y=fa[top[y]];
if(dep[x]<=dep[y])return x;
else return y;
}
struct Tree1{
int tree[2000005];
void build(int k,int l,int r){
if(l==r){
tree[k]=val[l];
return;
}
int mid=l+r>>1;
build(k*2,l,mid);
build(k*2+1,mid+1,r);
tree[k]=min(tree[k*2],tree[k*2+1]);
}
int query(int k,int l,int r,int x,int y){
if(l>=x&&r<=y)return tree[k];
int mid=l+r>>1;
if(y<=mid)return query(k*2,l,mid,x,y);
if(x>mid)return query(k*2+1,mid+1,r,x,y);
return min(query(k*2,l,mid,x,y),query(k*2+1,mid+1,r,x,y));
}
}T1;
struct Tree2{
int tree[2000005];
void update(int k,int l,int r,int x,int y){
if(l==r){
tree[k]=max(tree[k],y);
return;
}
int mid=l+r>>1;
if(x<=mid)update(k*2,l,mid,x,y);
else update(k*2+1,mid+1,r,x,y);
tree[k]=max(tree[k*2],tree[k*2+1]);
}
int query(int k,int l,int r,int x,int y){
if(l>=x&&r<=y)return tree[k];
int mid=l+r>>1;
if(y<=mid)return query(k*2,l,mid,x,y);
if(x>mid)return query(k*2+1,mid+1,r,x,y);
return max(query(k*2,l,mid,x,y),query(k*2+1,mid+1,r,x,y));
}
}T2;
int main(){
freopen("query.in","r",stdin);
freopen("query.out","w",stdout);
n=read();
for(int i=1;i<n;i++){
int x=read(),y=read();
edge[x].push_back(y);
edge[y].push_back(x);
}
dfs1(1,0);dfs2(1,1);
for(int i=1;i<=n;i++)a[++len]=(node){i,i,dep[i]};
for(int i=2;i<=n;i++)val[i]=dep[LCA(i-1,i)];
st[tp=0]=1;
for(int i=2;i<=n;i++){
while(tp&&val[st[tp]]>=val[i]){
a[++len]=(node){st[tp-1],i-1,val[st[tp]]};
tp--;
}
st[++tp]=i;
}
while(tp)a[++len]=(node){st[tp-1],n,val[st[tp]]},tp--;
sort(a+1,a+len+1);
T1.build(1,1,n);
m=read();
for(int i=1;i<=m;i++){
que[i].l=read(),que[i].r=read(),que[i].x=read(),que[i].id=i;
if(que[i].l<que[i].r)ans[i]=T1.query(1,1,n,que[i].l+1,que[i].r);
}
sort(que+1,que+m+1);
memset(T2.tree,0,sizeof(T2.tree));
for(int i=m,j=len;i>=1;i--){
while(j&&a[j].r-a[j].l+1>=que[i].x){
T2.update(1,1,n,a[j].l,a[j].x);
j--;
}
ans[que[i].id]=max(ans[que[i].id],T2.query(1,1,n,que[i].l,que[i].r-que[i].x+1));
}
memset(T2.tree,0,sizeof(T2.tree));
for(int i=m,j=len;i>=1;i--){
while(j&&a[j].r-a[j].l+1>=que[i].x){
T2.update(1,1,n,a[j].r,a[j].x);
j--;
}
ans[que[i].id]=max(ans[que[i].id],T2.query(1,1,n,que[i].l+que[i].x-1,que[i].r));
}
for(int i=1;i<=m;i++)printf("%d\n",ans[i]);
return 0;
}