#include<bits/stdc++.h>
#define ri register int
using namespace std;
int mex=0,s[2000005],q,n,id[500005],dep[500005],to[500005][2],fa[500005];
void js(ri x,ri l,ri r)
{
	if(l==r)
	{
		s[x]=dep[l];
		return;
	}
	ri mid=(l+r)>>1;
	js(x*2,l,mid);
	js(x*2+1,mid+1,r);
	s[x]=min(s[x*2],s[x*2+1]);
}
void cx(ri x,ri l,ri r,ri L,ri R)
{
	if(l>R||r<L)
	{
		return;
	}
	if(l>=L&&r<=R)
	{
		mex=max(mex,s[x]);
		return;
	}
	ri mid=(l+r)>>1;
	cx(x*2,l,mid,L,R);
	cx(x*2+1,mid+1,r,L,R);
	s[x]=min(s[x*2],s[x*2+1]);
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(ri i=1;i<n;++i)
	{
		ri u,v;
		scanf("%d%d",&u,&v);
		if(to[u][0]==0)
			to[u][0]=v;
		else
			to[u][1]=v;
		if(to[v][0]==0)
			to[v][0]=u;
		else
			to[v][1]=u;
	}
	ri ji=1,j=1;
	while(ji<=n)
	{
		dep[j]=ji;
		id[ji]=j;
		if(to[j][0]!=fa[j])
		{
			fa[to[j][0]]=j;
			j=to[j][0];
		}
		else
		{
			fa[to[j][1]]=j;
			j=to[j][1];
		}
		ji++;
	}
	js(1,1,n);
	scanf("%d",&q);
	while(q--)
	{
		ri l,r,k,ans=0;
		scanf("%d%d%d",&l,&r,&k);
		for(ri i=l;i<=r-k+1;++i)
		{
			ri j=i+k-1;
			mex=0;
			cx(1,1,n,i,j);
			ans=max(mex,ans);
		}
		printf("%d\n",ans);
	}
	return 0;
} 
