#include<bits/stdc++.h>
#define MAXN (int)5e5+10
using namespace std;
int ans,n,t,head[MAXN],cnt,dep[MAXN],siz[MAXN],maxsiz[MAXN],son[MAXN],top[MAXN],fa[MAXN];
struct node
{
	int nxt,to;
}e[MAXN<<1];
inline void add(int x,int y)
{
	e[++cnt]=(node){head[x],y};
	head[x]=cnt;
}
int q[MAXN],hd,tl;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-')
		{
			f=-1;
		}
		ch=getchar();
	}
	while(isdigit(ch))
	{
		x=(x<<3)+(x<<1)+(ch^'0');
		ch=getchar();
	}
	return x*f;
}
void dfs1(int x,int father)
{
	for(int i=head[x];i;i=e[i].nxt)
	{
		int y=e[i].to;
		if(y!=father)
		{
			dep[y]=dep[x]+1;
			fa[y]=x;
			dfs1(y,x);
			siz[x]+=siz[y];
			if(siz[y]>maxsiz[x])
			{
				son[x]=y;
				maxsiz[x]=siz[y];
			}
		}
	}
}
void dfs2(int x,int tmp)
{
	top[x]=tmp;
	if(!son[x])
	{
		return ;
	}
	dfs2(son[x],t);
	for(int i=head[x];i;i=e[i].nxt)
	{
		int y=e[i].to;
		if(y!=fa[x]&&y!=son[x])
		{
			dfs2(y,y);
		}
	}
}
int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]<dep[top[y]])
		{
			swap(x,y);
		}
		x=fa[top[x]];
	}
	if(dep[x]>dep[y])
	{
		swap(x,y);
	}
	return x;
}
signed main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n=read();
	for(int i=1;i<n;i++)
	{
		int x=read(),y=read();
		add(x,y);
		add(y,x);
	}
	for(int i=1;i<=n;i++)
	{
		siz[i]=1;
	}
	dep[1]=1;
	dfs1(1,0);
	dfs2(1,1);
	t=read();
	while(t--)
	{
		int l=read(),r=read(),k=read();
		ans=0;
		if(k==r-l+1)
		{
			if(l==r)
			{
				printf("%d\n",dep[l]);
				continue;
			}
			int tmp=lca(l,l+1);
			for(int i=l+2;i<=r;i++)
			{
				tmp=lca(tmp,i);
			}
			printf("%d\n",dep[tmp]);
			continue;
		}
		hd=tl=0;
		for(int i=l;i<=r;i++)
		{
			while(dep[q[hd]]>dep[i]&&hd>tl)
			{
				hd--;
			}
			q[++hd]=i;
			while(q[tl]<=i-k)
			{
				tl++;
			}
			ans=max(ans,dep[q[tl]]);
		}
		printf("%d\n",ans);
	}
	return 0;
}
//6
//5 6
//6 1
//6 2
//2 3
//2 4
