#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define ull unsigned long long
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i<+(k);i--)
#define ls u<<1
#define rs u<<1|1
bool SM;
const int N=1e5+10,mod=1e9+7,inf=0x3f3f3f3f;
int n,m,q,ans,T;
struct node{
int v,nx;
}e[N];
int hd[N],k;
void add(int u,int v){
e[++k]={v,hd[u]};
hd[u]=k;
}
int STola[N][25],STmn[N][25],STmx[N][25],tot,dep[N],lg2[N];
void dfs(int u,int fa){
dep[u]=dep[fa]+1;
for(int i=hd[u];i;i=e[i].nx){
if(e[i].v!=fa){
STola[++tot][0]=dep[u];
STmn[u][0]=STmx[u][0]=min(STmn[u][0],tot);
dfs(e[i].v,u);
}
}
STola[++tot][0]=dep[u];
STmn[u][0]=STmx[u][0]=min(STmn[u][0],tot);
}
void solve(){
cin>>n;
lg2[1]=0;
rep(i,2,n*3) lg2[i]=lg2[i>>1]+1;
rep(i,1,n) STmn[i][0]=STmx[i][0]=4*n+1;
rep(i,1,n-1){
int u,v;
cin>>u>>v;
add(u,v);
add(v,u);
}
dfs(1,0);
rep(x,1,20){
rep(i,1,n-(1<<x)+1){
STmx[i][x]=max(STmx[i][x-1],STmx[i+(1<<(x-1))][x-1]);
STmn[i][x]=min(STmn[i][x-1],STmn[i+(1<<(x-1))][x-1]);
}
}
rep(x,1,20){
rep(i,1,tot-(1<<x)+1){
STola[i][x]=min(STola[i][x-1],STola[i+(1<<(x-1))][x-1]);
}
}
cin>>q;
while(q--){
int L,R,K,MAX=0;
cin>>L>>R>>K;
rep(i,L,R-K+1){
int l=i,r=K+i-1;
int LG2=lg2[r-l+1];
int Min=min(STmn[l][LG2],STmn[r-(1<<LG2)+1][LG2]),
Max=max(STmx[l][LG2],STmx[r-(1<<LG2)+1][LG2]);
LG2=lg2[Max-Min+1];
MAX=max(MAX,min(STola[Min][LG2],STola[Max-(1<<LG2)+1][LG2]));
}
cout<<MAX<<'\n';
}
}
bool EM;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
freopen("query.in","r",stdin);
freopen("query.out","w",stdout);
T=1;
while(T--) solve();
return 0;
}