#include <bits/stdc++.h>
#define N int(3e5+10)
#define M 21
#define pb push_back
using namespace std;
int s[N][M],p[N],l[N],n,q,u,v;
vector<int>g[N];
void dfs(int s,int pr){
p[s]=pr;
if(pr)
l[s]=l[pr]+1;
for(int i=0;i<g[s].size();i++)
if(g[s][i]!=pr)
dfs(g[s][i],s);
}
void pre(){
for(int i=0;i<=n;i++)
for(int j=0;j<M;j++)
s[i][j]=0;
for(int i=1;i<=n;i++)
s[i][0]=p[i];
for(int j=1;(1<<j)<M;j++){
for(int i=1;i<=n;i++)
s[i][j]=s[s[i][j-1]][j-1];
}
}
int f(int a, int d){
int logn=0,b=a;
while((1<<logn)<=d)
logn++;
logn--;
while(d){
if(d&(1<<logn)){
d-=(1<<logn);
b=s[b][logn];
}
logn--;
}
return b;
}
int lca(int u,int v){
if(l[u]<l[v])
swap(u,v);
u=f(u,l[u]-l[v]);
if(u==v)
return u;
int logn=0;
while((1<<logn)<=l[v])
logn++;
logn--;
while(logn>=0){
if(s[u][logn]&&(s[u][logn]!=s[v][logn])){
u=s[u][logn];
v=s[v][logn];
}
logn--;
}
return p[u];
}
int main() {
scanf("%d",&n);
for(int i=1;i<n;i++){
scanf("%d%d",&u,&v);
g[u].pb(v);
g[v].pb(u);
}
dfs(1,0);
pre();
cin>>q;
while(q--){
int a,b,c,ans;
scanf("%d%d%d",&a,&b,&c);
int lc=lca(a,b);
int d=l[a]+l[b]-2*l[lc],d1;
if(c>=d){
ans=b;
}else{
if(a==lc){
ans=f(b,d-c);
}else{
d1=l[a]-l[lc];
if(c>=d1){
c-=d1;
ans=f(b,l[b]-l[lc]-c);
}else{
ans=f(a,c);
}
}
}
printf("%d\n",ans);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgTiBpbnQoM2U1KzEwKQojZGVmaW5lIE0gMjEKI2RlZmluZSBwYiBwdXNoX2JhY2sKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IHNbTl1bTV0scFtOX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