#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
struct QUE{
	int l,r,k;
};QUE que[N];
struct Date{
	int ma,mi;
};Date tr[N*4],key;
int tot,he[N],ne[N*2],to[N*2],fa[N],top[N],dfn[N],h[N],ti,de[N],siz[N],ans[N];
int read()
{
	int s=0;char ch=getchar();
	while(ch<'0'||ch>'9')
	ch=getchar();
	while(ch>='0'&&ch<='9')
	{
		s=(s<<3)+(s<<1)+int(ch-'0');
		ch=getchar();
	}
	return s;
}
void dfs(int x)
{
	int i,y;siz[x]=1;
	for(i=he[x];i!=0;i=ne[i])
	{
		y=to[i];
		if(y!=fa[x])
		{
			fa[y]=x;de[y]=de[x]+1;dfs(y);siz[x]+=siz[y];
		}
	}
}
void build(int x)
{
	int i,y,ma=-1,k;dfn[x]=++ti;h[ti]=x;
	for(i=he[x];i!=0;i=ne[i])
	{
		y=to[i];
		if(y!=fa[x]&&siz[y]>ma)
		{
			ma=siz[y];k=y;
		}
	}
	if(ma==-1)
	return;
	top[k]=top[x];build(k);
	for(i=he[x];i!=0;i=ne[i])
	{
		y=to[i];
		if(y!=fa[x]&&y!=k)
		{
			top[y]=y;build(y);
		}
	}
}
void Build(int l,int r,int tot)
{
	if(l==r)
	{
		tr[tot].ma=tr[tot].mi=dfn[l];return;
	}
	int mid=(l+r)>>1,y=tot<<1,z=y|1;
	Build(l,mid,y);Build(mid+1,r,z);
	tr[tot].ma=max(tr[y].ma,tr[z].ma);
	tr[tot].mi=min(tr[y].mi,tr[z].mi);
}
void cz(int x,int y,int l,int r,int tot)
{
	if(x<=l&&r<=y)
	{
		key.ma=max(tr[tot].ma,key.ma);key.mi=min(tr[tot].mi,key.mi);
		return;
	}
	int mid=(l+r)>>1;
	if(x<=mid)
	cz(x,y,l,mid,tot<<1);
	if(mid<y)
	cz(x,y,mid+1,r,tot<<1|1);
}
int Lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(de[top[x]]>de[top[y]])
		x=fa[top[x]];
		else
		y=fa[top[y]];
	}
	if(de[x]<de[y])
	return x;
	return y;
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	int n,m,i,j,x,y,l,r,k;
	n=read();
	for(i=1;i<n;i++)
	{
		x=read();y=read();
		tot++;ne[tot]=he[x];to[tot]=y;he[x]=tot;
		tot++;ne[tot]=he[y];to[tot]=x;he[y]=tot;
	}
	m=read();
	for(i=1;i<=m;i++)
	{
		que[i].l=read();que[i].r=read();que[i].k=read();
	}
	top[1]=1;de[1]=1;dfs(1);build(1);Build(1,n,1);
	for(i=1;i<=m;i++)
	{
		l=que[i].l;k=que[i].k;r=que[i].r-k+1;
		for(j=l;j<=r;j++)
		{
			key.ma=0;key.mi=1e9;
			cz(j,j+k-1,1,n,1);
			ans[i]=max(ans[i],de[Lca(h[key.ma],h[key.mi])]);
		}
	}
	for(i=1;i<=m;i++)
	printf("%d\n",ans[i]);
	return 0;
}
