#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int tree[500005];
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	int n,q,l,r,k,ans;
	cin>>n;
	for(int i=1,x,y;i<n;i++){
		cin>>x>>y;
		tree[i]=x;
		tree[i+1]=y;
	}
	cin>>q;
	for(int i=1;i<=q;i++){
		ans=-1;
		cin>>l>>r>>k;
		for(int j=l;j<=r;j++){
			for(int m=1;m<=n;k++){
				if(tree[m]==j||tree[m]==j+k){
					ans=max(ans,m);
					break;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
