#include<bits/stdc++.h>
using namespace std;
int n,q,deep[500010],allson[500010],root[500010],fa[500010];
int cnt;
bool vis[500010];
vector<int> road[500010];
void dfs1(int p,int fath){
fa[p]=fath;
allson[p]=0;
if(road[p].size()==1&&p!=1){
return;
}
for(int i=0;i<road[p].size();i++){
int nxt=road[p][i];
if(nxt==fa[p]) continue;
deep[nxt]=deep[p]+1;
dfs1(nxt,p);
allson[p]+=allson[nxt]+1;
}
}
void dfs2(int p,int roo){
root[p]=roo;
if(road[p].size()==1&&p!=1) return;
int maxi=0,maxx=-1;
for(int i=0;i<road[p].size();i++){
int nxt=road[p][i];
if(nxt==fa[p]) continue;
if(allson[nxt]>maxx) {
maxx=allson[nxt];
maxi=nxt;
}
}
if(maxi!=0){
dfs2(maxi,roo);
}
for(int i=0;i<road[p].size();i++){
int nxt=road[p][i];
if(nxt==fa[p]||nxt==maxi) continue;
dfs2(nxt,nxt);
}
}
int lca(int x,int y){
while(root[x]!=root[y]){
if(deep[root[x]]>deep[root[y]]){
x=fa[root[x]];
}
else y=fa[root[y]];
}
if(deep[x]>deep[y]) return y;
return x;
}
int t[2000010];
int ls(int p){return p*2;}
int rs(int p){return p*2+1;}
void push_up(int p){ t[p]=lca(t[ls(p)],t[rs(p)]);}
void build(int p,int l,int r){
if(l==r){
t[p]=l;
return;
}
int mid=(l+r)/2;
build(ls(p),l,mid);
build(rs(p),mid+1,r);
push_up(p);
}
int query(int p,int l,int r,int nl,int nr){
if(nl<=l&&r<=nr) return t[p];
int mid=(l+r)/2;
int a=0,b=0;
if(mid>=nl) a=query(ls(p),l,mid,nl,nr);
if(mid+1<=nr) b=query(rs(p),mid+1,r,nl,nr);
if(a!=0&&b!=0) return lca(a,b);
if(a) return a;
if(b) return b;
}
int read(){
char c;int flaggg=1,ans=0;
c=getchar();
while(c<'0'||c>'9'){
if(c=='-') flaggg=-1;
c=getchar();
}
while('0'<=c&&c<='9'){
ans=ans*10+c-'0';
c=getchar();
}
return ans*flaggg;
}
void print(int g){
if(g<0){
putchar('-');
g*=-1;
}
if(g<10){
putchar(g+'0');
}
else{
print(g/10);
putchar(g%10+'0');
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
freopen("query.in","r",stdin);
freopen("query.out","w",stdout);
cin>>n;
if(n>=100001){
for(int i=1;i<=n-1;i++){
int u=read(),v=read();
road[u].push_back(v);
road[v].push_back(u);
}
}
else{
for(int i=1;i<=n-1;i++){
int u,v;
cin>>u>>v;
road[u].push_back(v);
road[v].push_back(u);
}
}
cin>>q;
int cnt=0;
for(int i=1;i<=n;i++){
if(road[i].size()>=3){
cnt=-1;
break;
}
if(road[i].size()==1) cnt++;
}
deep[1]=1;
dfs1(1,0);
dfs2(1,1);
build(1,1,n);
if(n>=100001){
while(q--){
int l=read();
int r=read();
int k=read();
int maxx=-1;
for(int i=l;i+k-1<=r;i++){
int j=i+k-1;
int g=query(1,1,n,i,j);
maxx=max(maxx,deep[g]);
}
print(maxx);
putchar('\n');
}
}
else{
while(q--){
int l,r,k;
cin>>l>>r>>k;
int maxx=-1;
for(int i=l;i+k-1<=r;i++){
int j=i+k-1;
int g=query(1,1,n,i,j);
maxx=max(maxx,deep[g]);
}
cout<<maxx<<'\n';
}
}
return 0;
}