#include<bits/stdc++.h>
#include<vector>
using namespace std;
long long n,u,v,l,r,k,dep[1000000],fa[1000000],ans=0,q,g;
long long find(int x){
	if(fa[x]==x){
		dep[x]=1;
		return fa[x];
	}else{
		fa[x]=find(fa[x]);
		dep[x]=dep[fa[x]]+1; 
		return fa[x];
	}
}
long long lca(int l,int r){
	int sum=l,min=dep[l];
	for(int i=l;i<=r;i++){
		if(dep[i]<=min){
			sum=i;
			min=dep[i]; 
		}
	}
	return dep[sum];
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=n-1;i++){
		scanf("%lld",&u);
		scanf("%lld",&v);
		fa[u]=v;
	}
	
	fa[1]=1;
	for(int i=1;i<=n;i++){
		find(i);
	}
	scanf("%lld",&q);
	for(int i=1;i<=q;i++){
		scanf("%lld%lld%lld",&l,&r,&k);
		for(int j=l;j+k-1<=r;j++){
			ans=max(ans,lca(j,j+k-1));
		}
		printf("%lld",ans);
		cout<<"\n";
	}
}
