#include<cstdio>
using namespace std;
const int N=1e4+10;
int map[N][N];
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	int n;
	scanf("%d",&n);
	for(int i=0;i<N;i++)	
		for(int j=0;j<N;j++)
			map[i][j]=0;
	for(int i=1;i<=n-1;i++)
	{
		int u,v;
		scanf("%d %d",&u,&v);
		map[u][v]=map[v][u]=1;
	}
	int q;
	scanf("%d",&q);
	for(int i=1;i<=q;i++)
	{
		int l,r,k;
		scanf("%d %d %d",&l,&r,&k);
		printf("%d\n",l);
	}
}
