#include<bits/stdc++.h>
using namespace std;
struct op{
int x,y;
op(const int&aa=0,const int&bb=0):x(aa),y(bb){}
bool operator<(const op&aa)const{return x>aa.x;}
}a[500005],l[1000005];
struct po{
int x,y,z;
po(const int&aa=0,const int&bb=0,const int&cc=0):x(aa),y(bb),z(cc){}
bool operator<(const po&aa)const{return y>aa.y;}
}st[1000005];
struct oo{
int x,o,i,z;
oo(const int&aa=0,const int&bb=0,const int&cc=0,const int&dd=0):x(aa),o(bb),i(cc),z(dd){}
bool operator<(const oo&aa)const{return x>aa.x;}
}b[500005];
int s,d,f,o,i,p,ax[500005],bx[1000005],cx[1000005],de[500005],ff[1000005][20],t0,fa[1000005],ft[1000005],q[1000005],si,ky[2000005],an[500005];
template<typename T>inline void read(T &n){
T w=1;n=0;char ch=getchar();
while(!isdigit(ch)&&ch!=EOF){if(ch=='-')w=-1;ch=getchar();}
while(isdigit(ch)&&ch!=EOF)n=(n<<1)+(n<<3)+(ch&15),ch=getchar();
n*=w;
}
void dfs(int x){
for(int g=ax[x];g;g=bx[g])if(cx[g]!=fa[x])fa[cx[g]]=x,de[cx[g]]=de[x]+1,dfs(cx[g]);
}
int lca(int x,int y){
if(de[x]<de[y])swap(x,y);int t=t0;while(t>=0){if(de[ff[x][t]]>=de[y])x=ff[x][t];t--;}if(x==y)return x;t=t0;
while(t>=0){if(ff[x][t]!=ff[y][t])x=ff[x][t],y=ff[y][t];t--;}return fa[x];
}
int fi(int x){if(fa[x]==x)return x;return fa[x]=fi(fa[x]);}
void he(int x,int y,int z){
f++,fa[x]=f,fa[y]=f,ft[x]=f,ft[y]=f,l[f]=op(l[x].x,l[y].y),q[f]=z,st[++si]=po(l[x].x,l[y].y-l[x].x+1,z);
}
void gai(int x,int y,int z,int o,int i){
ky[z]=max(ky[z],i);if(x==y)return;int mid=(x+y)>>1;if(o<=mid)gai(x,mid,z<<1,o,i);else gai(mid+1,y,z<<1|1,o,i);
}
int cha(int x,int y,int z,int o,int i){
if(o<=x&&y<=i)return ky[z];int mid=(x+y)>>1,kk=0;if(o<=mid)kk=cha(x,mid,z<<1,o,i);if(i>mid)kk=max(kk,cha(mid+1,y,z<<1|1,o,i));return kk;
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
freopen("query.in","r",stdin);
freopen("query.out","w",stdout);
read(s);
for(int g=1;g<s;g++)read(o),read(i),bx[g*2-1]=ax[o],ax[o]=g*2-1,cx[g*2-1]=i,bx[g*2]=ax[i],ax[i]=g*2,cx[g*2]=o;
de[1]=1,dfs(1);
for(int g=1;g<=s;g++)ff[g][0]=fa[g];
for(int g=1;1<<g<=s;g++){for(int h=1;h<=s;h++)ff[h][g]=ff[ff[h][g-1]][g-1];t0=g;}
for(int g=1;g<s;g++)a[g].x=de[lca(g,g+1)],a[g].y=g;sort(a+1,a+s);
for(int g=1;g<=2*s;g++)fa[g]=g;f=s;
for(int g=1;g<=s;g++)l[g]=op(g,g),st[++si]=po(g,1,de[g]);
for(int g=1;g<s;g++){
int e=fi(a[g].y),r=fi(a[g].y+1);
he(e,r,a[g].x);
}
for(int g=1;g<=f;g++)ff[g][0]=ft[g];
for(int g=1;1<<g<=f;g++){for(int h=1;h<=f;h++)ff[h][g]=ff[ff[h][g-1]][g-1];t0=g;}
read(d);
for(int g=1;g<=d;g++){
read(o),read(i),read(p),b[g]=oo(p,o,i-p+1,g);
int kk=o,t=t0;
while(t>=0){
if(ff[kk][t]&&l[ff[kk][t]].y-o+1<p)kk=ff[kk][t];
t--;
}
if(p>1)an[g]=q[ft[kk]];
}
sort(st+1,st+1+si),sort(b+1,b+1+d);int kk=1,k1=1;
for(int g=s;g;g--){
while(kk<=si&&st[kk].y==g)gai(1,s,1,st[kk].x,st[kk].z),kk++;
while(k1<=d&&b[k1].x==g)an[b[k1].z]=max(an[b[k1].z],cha(1,s,1,b[k1].o,b[k1].i)),k1++;
}
for(int g=1;g<=d;g++)cout<<an[g]<<'\n';
return 0;
}