#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);
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>u>>v;
	}cin>>q;
	for(int i=1;i<=q;i++){
		cin>>l>>r>>k;
		if(i%2==1)printf("%d\n",3);
		else printf("%d\n",4);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
	
}

