#include<bits/stdc++.h>
using namespace std;
inline int rd(){
char c=getchar();int s=0;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) s=s*10+c-48,c=getchar();
return s;
}
const int N=500005,M=1<<19;
int n,q,i,x,y,tot,lst[N],dep[N],top,st1[N],st2[N];
struct edg{
int y,n;
}d[N<<1];
void cun(int x,int y){d[++tot]=edg{y,lst[x]};lst[x]=tot;}
int dfn[N],ed[N],num,ST[20][N];
void dfs(int x,int fa){
dfn[x]=++num;ST[0][num]=fa;
for(int j=lst[x];j;j=d[j].n) if(d[j].y^fa) dep[d[j].y]=dep[x]+1,dfs(d[j].y,x);
ed[x]=num;
}
inline bool in(int x,int y){return dfn[x]<=dfn[y]&&ed[x]>=dfn[y];}
inline int LCA(int x,int y){
if(x==y) return x;
x=dfn[x],y=dfn[y];
if(x>y) swap(x,y);
int t=__lg(y-x);
return dep[ST[t][x+1]]<dep[ST[t][y-(1<<t)+1]]?ST[t][x+1]:ST[t][y-(1<<t)+1];
}
int len;
struct node{
int l,r,v,id;
}f[N<<1],g[N];
bool cmp(node a,node b){return a.r>b.r;}
bool cmp2(node a,node b){return a.v>b.v;}
bool cmp3(node a,node b){return a.r-a.l+1>b.r-b.l+1;}
int tr[N],ans[N];
inline void ad(int k,int x){while(k<=n) tr[k]=max(tr[k],x),k+=-k&k;}
inline int he(int k){int ret=0;while(k) ret=max(ret,tr[k]),k-=-k&k;return ret;}
int mx[M<<1];
inline void ad2(int k,int x){k+=M;while(k) mx[k]=max(mx[k],x),k>>=1;}
inline int he2(int l,int r){
int ret=0;
for(l+=M-1,r+=M+1;l^r^1;l>>=1,r>>=1){
if(r&1) ret=max(ret,mx[r^1]);
if(~l&1) ret=max(ret,mx[l^1]);
}
return ret;
}
int main()
{
freopen("query.in","r",stdin);
freopen("query.out","w",stdout);
scanf("%d",&n);
for(i=1;i<n;i++) x=rd(),y=rd(),cun(x,y),cun(y,x);
dep[1]=1,dfs(1,0);
for(i=1;i<19;i++)
for(int j=1;j+(1<<i)-1<=n;j++)
ST[i][j]=dep[ST[i-1][j]]<dep[ST[i-1][j+(1<<i-1)]]?ST[i-1][j]:ST[i-1][j+(1<<i-1)];
st1[1]=st2[1]=top=1;
for(i=2;i<=n;i++){
while(top&&!in(st1[top],i)){
f[++len]=node{st2[top],i-1,dep[st1[top]],0};
top--;
}
int u=LCA(i,i-1);
if(u==st1[top]){
++top,st1[top]=st2[top]=i;
}
else{
++top,st1[top]=u;
if(u^i) ++top,st1[top]=st2[top]=i;
}
}
while(top){
f[++len]=node{st2[top],n,dep[st1[top]],0};
top--;
}
scanf("%d",&q);
for(i=1;i<=q;i++) g[i].l=rd(),g[i].r=rd(),g[i].v=rd(),g[i].id=i;
reverse(f+1,f+len+1);
sort(g+1,g+q+1,cmp);
for(int i=1,j=1;i<=q;i++){
while(j<=len&&f[j].r>=g[i].r) ad(f[j].l,f[j].v),j++;
ans[g[i].id]=he(g[i].r-g[i].v+1);
}
sort(f+1,f+len+1,cmp3);
sort(g+1,g+q+1,cmp2);
for(int i=1,j=1;i<=q;i++){
while(j<=len&&f[j].r-f[j].l+1>=g[i].v) ad2(f[j].r,f[j].v),j++;
ans[g[i].id]=max(ans[g[i].id],he2(g[i].l+g[i].v-1,g[i].r));
}
for(i=1;i<=q;i++) printf("%d\n",ans[i]);
return 0;
}