#include <iostream>
#include <string>
#include <vector>
using  namespace std;
int n,cnt=0;
const int N=500005;
int head[N];
struct Edge{
	int v,nxt;
} edge[(N<<1)+5];
void add(int u,int v){
	edge[++cnt]={v,head[u]};
	head[u]=cnt;
}
int depth[N];
int logn[N];
int father[N][20];
void caluDepth(int u,int fa){
	depth[u]=depth[fa]+1;
	father[u][0]=fa;
	//cout<<depth[u]<<'\n';
	for(int i=1;i<20;i++){
		father[u][i]=father[father[u][i-1]][i-1];
	}
	for(int i=head[u];i;i=edge[i].nxt){
		if(edge[i].v==fa) continue;
		caluDepth(edge[i].v,u);
	}
}
int q;
int lca(int a,int b){
	if(a==b) return a;
	if(depth[a]<depth[b]) swap(a,b);
	while(depth[a]>depth[b]){
		a=father[a][logn[depth[a]-depth[b]]];
	}
	if(a==b) return a;
	int fa,fb;
	for(int i=logn[depth[a]];i>=0;i--){
		fa=father[a][i];
		fb=father[b][i];
		if(fa!=fb) a=fa,b=fb,i=logn[depth[a]];
	}
	
	if(fa==fb) return father[a][0];
	return father[fa][0];
}
int que(int l,int r){
	//if(l==r) return depth[l];
	int ans=N,s=l;
	for(int i=l;i<=r;i++){
		int tmp=lca(s,i);
		//printf("%d %d lca(%d,%d)=%d\n",l,r,s,i,tmp);
		s=tmp;	
	}
	return s;
}
void solve(){
	int l,r,k;
	cin>>l>>r>>k;
	int ans=0;
	for(int i=l;i+k-1<=r;i++){
		int tmp=que(i,i+k-1);
		//printf("que(%d,%d)=%d\n",i,i+k-1,tmp);
		ans=max(ans,depth[tmp]);
	}
	cout<<ans<<'\n';
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin>>n;
	int u,v;
	logn[1]=0;
	for(int i=1;i<=n-1;i++){
		cin>>u>>v;
		//cout<<i<<' '<<cnt<<'\n';
		add(u,v);
		add(v,u);
		logn[i+1]=logn[(i+1)>>1]+1;
	}
	caluDepth(1,0);
	//printf("lca(%d,%d)=%d\n",1,2,lca(1,2));
	cin>>q;
	while(q--){
		solve();
	}
	return 0;
}
