#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=5e5+5,maxm=20;
int n,Q;
struct edge
{
	int ev,enex;
}e[maxn<<2];
int head[maxn],tote=0;
void add(int u,int v){e[++tote].ev=v,e[tote].enex=head[u],head[u]=tote;}
int dep[maxn],lg[maxn],anc[maxn][maxm];
void init()
{
	lg[1]=0;
	for(int i=2;i<=n;i++)	lg[i]=lg[i>>1]+1;
}
void dfs1(int x,int Fa)
{
	dep[x]=dep[Fa]+1,anc[x][0]=Fa;
	for(int i=1;i<=lg[dep[x]];i++)
	{
		anc[x][i]=anc[anc[x][i-1]][i-1];
	}
	for(int i=head[x],y;i;i=e[i].enex)
	{
		y=e[i].ev;
		if(y==Fa)	continue;
		dfs1(y,x);
	}
}
int LCA(int x,int y)
{
	if(dep[x]<dep[y])	swap(x,y);
	while(dep[x]!=dep[y])
	{
		x=anc[x][lg[dep[x]-dep[y]]];
	}
	if(x==y)	return x;
	for(int i=lg[dep[x]];i>=0;i--)
	{
		if(anc[x][i]!=anc[y][i])	x=anc[x][i],y=anc[y][i];
	}
	return anc[x][0];
}
int tr[maxn<<4];
void build(int l,int r,int w)
{
	if(l==r)	{tr[w]=l;return ;}
	int mid=(l+r)>>1;
	build(l,mid,w<<1),build(mid+1,r,w<<1|1);
	tr[w]=LCA(tr[w<<1],tr[w<<1|1]);
}
int query(int l,int r,int w,int L,int R)
{
	if(l>=L&&r<=R)	return tr[w];
	int mid=(l+r)>>1,res1=0,res2=0;
	if(L<=mid)	res1=query(l,mid,w<<1,L,R);
	if(mid+1<=R)	res2=query(mid+1,r,w<<1|1,L,R);
	if(res1&&res2)	return LCA(res1,res2);
	else	return res1?res1:res2;
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i=1,u,v;i<=n-1;i++)
	{
		scanf("%d%d",&u,&v);
		add(u,v),add(v,u);
	}
	init();
	dep[0]=-1;
	dfs1(1,0);
	build(1,n,1);
	scanf("%d",&Q);
	while(Q--)
	{
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		printf("%d\n",dep[query(1,n,1,l,r)]+1);
	}
	return 0;
}
/*
6
5 6
6 1
6 2
2 3
2 4
3
3 4 2
4 5 1
1 6 3
*/
