#include<bits/stdc++.h>
using namespace std;
int a[1145141],ma[4114514],b[1145141];
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	int n;
	a[1]=1;
	scanf("%d",&n);
	for(int i=1;i<=n-1;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		a[y]=i+1;
	}
	int q;
	scanf("%d",&q);
	for(int i=1;i<=q;i++)
	{
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		for(int j=l;j<=r;j++)
		{
			b[j]=a[j];
		}
		sort(b+l+1,b+r+1);
		  printf("%d\n",b[r-k+1]);
	}//rp++;
	return 0;
 } 
