#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
long long n,m,dep[N],fa[N],l,r,k;
vector<int>q[N];
struct node{
int mn;
}tree[N*4+5];
void build(int l,int r,int id)
{
if(l==r)
{
tree[id].mn=dep[l];
return;
}
int mid=(l+r)/2;
build(l,mid,id*2);
build(mid+1,r,id*2+1);
tree[id].mn=min(tree[id*2].mn,tree[id*2+1].mn);
}
long long cz(int l,int r,int nl,int nr,int id)
{
if(nl<=l&&r<=nr)
return tree[id].mn;
int mid=(l+r)/2;
long long ans=1e18;
if(mid>=nl) ans=min(ans,cz(l,mid,nl,nr,id*2));
if(mid<nr) ans=min(ans,cz(mid+1,r,nl,nr,id*2+1));
return ans;
}
void dfs(int i)
{
dep[i]=dep[fa[i]]+1;
for(int j=0;j<q[i].size();++j)
{
if(fa[i]==q[i][j]) continue;
fa[q[i][j]]=i;
dfs(q[i][j]);
}
}
int main()
{
freopen("query.in","r",stdin);
freopen("query.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<n;++i)
cin>>l>>r,q[l].push_back(r),q[r].push_back(l);
dfs(1);
build(1,n,1);
cin>>m;
for(int i=1;i<=m;++i)
{
cin>>l>>r>>k;
cout<<max(cz(1,n,l,l+k-1,1),cz(1,n,r-k+1,r,1))<<'\n';
}
return 0;
}