#include<bits/stdc++.h>
using namespace std;
int n,u,v,q,l,r,k;
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n-1;i++){
		scanf("%d%d",&u,&v);
	}
	scanf("%d",&q);
	while(q--){
		scanf("%d%d%d",&l,&r,&k);
		printf("%d\n",r);
	}
	return 0;
} 
