#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=5e5+7;
int a[N],b[N],dep[N],anc[N][22],lst[N],nxt[2*N],to[2*N];
int n,m,k,q,t,cnt,tmp,sum,ans,mx=-1e9,x,y,z,w,l,r,mid,f;
void add(int x,int y){
	to[++cnt]=y,nxt[cnt]=lst[x],lst[x]=cnt;
}
void dfs1(int x,int y){
	dep[x]=dep[y]+1,anc[x][0]=y;
	for(int i=1;i<=log2(dep[x]);i++)anc[x][i]=anc[anc[x][i-1]][i-1];
	for(int j=lst[x];j;j=nxt[j]){
		int i=to[j];
		if(i!=y)dfs1(i,x);
	}
}
int lca(int x,int y){
	if(x==y)return x;
	if(dep[x]<dep[y])swap(x,y);
	for(int i=log2(dep[x]-dep[y]);i>=0;i--){
		if(dep[anc[x][i]]>=dep[y])x=anc[x][i];
	}
	if(x==y)return x;
	for(int i=log2(dep[x]);i>=0;i--){
		if(anc[x][i]!=anc[y][i])x=anc[x][i],y=anc[y][i];
	}
	return anc[x][0];
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin>>n;
	for(int i=1;i<n;i++)scanf("%d%d",&x,&y),add(x,y),add(y,x);
	dfs1(1,0);
	cin>>q;
	while(q--){
		scanf("%d%d%d",&l,&r,&k),ans=0;
		for(int i=l;i<=r-k+1;i++){
			int x=i,dp=dep[x];
			for(int j=i+1;j<=i+k-1;j++){
				if(ans>=dp)break;
			//	cout<<x<<" "<<j<<" ",
				x=lca(x,j),dp=dep[x];//cout<<dp<<" ";
			}//cout<<"\n";
			ans=max(ans,dp);
		}
		printf("%d\n",ans);
	}
	return 0;
}
