#include<iostream>
#include<cmath>
using namespace std;
int len[500005];
int tr[500005][3];
int r[500005];
int x[10001],y[10001],mn[10001],sum,l,d[500005],n;
void test(){
	cout<<l<<" "<<sum<<endl;
	for(int i=1;i<=n;i++) cout<<d[i]<<" ";
	cout<<endl;
	for(int i=1;i<=sum;i++){
		cout<<x[i]<<" "<<y[i]<<" "<<mn[i]<<endl;
	}
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin>>n;
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		len[u]++; len[v]++;
		tr[u][len[u]]=v; tr[v][len[v]]=u;
	}
	r[1]=1;
	int id=1;
	for(int i=2;i<=n;i++){
		int a=tr[id][1],b=tr[id][2];
		if(a!=0&&r[a]==0){
			r[a]=i;
			id=a;
		}
		else{
			r[b]=i;
			id=b;
		}
	}
	l=sqrt(n); sum=n/l;
	for(int i=1;i<=n;i++) d[i]=(i+1)/l;
	for(int i=1;i<=sum;i++){
		x[i]=l*(i-1)+1;
		y[i]=l*i;
		mn[i]=n+1;
		for(int j=x[i];j<=y[i];j++){
			if(r[j]<mn[i]) mn[i]=r[j];
		}
	}
	if(l*sum<n){
		mn[sum+1]=n+1;
		x[sum+1]=l*sum+1;
		y[sum+1]=n;
		for(int i=x[sum+1];i<=y[sum+1];i++){
			if(r[i]<mn[sum+1]) mn[sum+1]=r[i];
		}
		sum++;
	}
	int q;
	cin>>q;
	while(q--){
		int l0,r0,k0;
		cin>>l0>>r0>>k0;
		int ans=0;
		for(int i=l0;i<=r0;i++){
			int j=l0+k0-1;
			if(j>r0) break;
			if(k0<2*l){
				int minn=n+1;
				for(int k=i;k<=j;k++){
					if(r[k]<minn) minn=r[k];
				}
				if(minn>ans) ans=minn;
			}
			else{
				int minn=n+1;
				for(int k=i;k<=y[d[i]];k++){
					if(r[k]<minn) minn=r[k];
				}
				for(int k=x[d[j]];k<=j;k++){
					if(r[k]<minn) minn=r[k];
				}
				for(int k=d[i]+1;k<=d[j]-1;k++){
					if(mn[k]<minn) minn=mn[k];
				}
				if(minn>ans) ans=minn;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
