#include<bits/stdc++.h>
using namespace std;
struct edge{
	int to,nxt;
}e[1000001];
int head[500001],cnt;
void add(int u,int v){
	cnt++;
	e[cnt].to=v;
	e[cnt].nxt=head[u];
	head[u]=cnt;
}
int f[500001],siz[500001],dep[500001],son[500001];
void dfs1(int x,int fa){
	f[x]=fa,siz[x]=1,dep[x]=dep[fa]+1;
	for(int i=head[x];i;i=e[i].nxt){
		int v=e[i].to;
		if(v==fa) continue;
		dfs1(v,x);
		siz[x]+=siz[v];
		if(siz[v]>siz[son[x]]) son[x]=v;
	}
}
int top[500001];
void dfs2(int x,int tp){
	top[x]=tp;
	if(son[x]) dfs2(son[x],tp);
	for(int i=head[x];i;i=e[i].nxt){
		int v=e[i].to;
		if(v==f[x]||v==son[x]) continue;
		dfs2(v,v);
	}
}
int lca(int x,int y){
	while(top[x]!=top[y]){
		if(dep[top[x]]<dep[top[y]]) swap(x,y);
		x=f[top[x]];
	}
	if(dep[x]>dep[y]) swap(x,y);
	return x;
}
int tp[500001][21];
int n,q;
int lg[500001];
int qlca(int l,int r){
	int len=lg[r-l+1];
	return lca(tp[l][len],tp[r-(1<<len)+1][len]);
}
signed main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0); 
	cin>>n;
	for(int i=1,u,v;i<n;i++){
		cin>>u>>v;
		add(u,v);
		add(v,u);
	}
	dfs1(1,0);
	dfs2(1,1);
	for(int i=1;i<=n;i++) tp[i][0]=i;
	lg[0]=-1;
	for(int i=1;i<=n;i++) lg[i]=lg[i/2]+1;
	for(int j=1;j<=lg[n];j++){
		for(int i=1;i+(1<<j)-1<=n;i++) tp[i][j]=lca(tp[i][j-1],tp[i+(1<<(j-1))][j-1]);
	}
	cin>>q;
	while(q--){
		int l,r,k;
		cin>>l>>r>>k;
		int ans=0;
		for(int i=l;i+k-1<=r;i++) ans=max(ans,dep[qlca(i,i+k-1)]);
		cout<<ans<<"\n";
	}
}
