#include<cstdio>
#include<iostream>
#include<cstring>
#define re register
using namespace std;
const int N=5e5+5;
int n,q,ans;
int head[N],Next[N<<1],to[N<<1];
int dep[N],fa[N],siz[N],son[N];
int top[N],dfn[N],id[N];
inline void add(re int u,re int v)
{
	Next[++head[0]]=head[u];
	head[u]=head[0];
	to[head[0]]=v;
}
inline void dfs1(re int x,re int ba)
{
	siz[x]=1;
	for(re int i=head[x];i;i=Next[i])
	{
		re int y=to[i];
		if(y!=ba)
		{
			fa[y]=x;
			dep[y]=dep[x]+1;
			dfs1(y,x);
			siz[x]+=siz[y];
			if(siz[son[x]]<siz[y]) son[x]=y;
		}
	}
}
inline void dfs2(re int x,re int rk)
{
	top[x]=rk;
	dfn[x]=++dfn[0];
	id[dfn[0]]=x;
	if(son[x]) dfs2(son[x],rk);
	for(re int i=head[x];i;i=Next[i])
	{
		re int y=to[i];
		if(y!=fa[x]&&y!=son[x])
			dfs2(y,y);
	}
}
inline int LCA(re int x,re 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]) return y;
	else return x;
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(re int i=1,u,v;i<n;++i)
	{
		scanf("%d%d",&u,&v);
		add(u,v),add(v,u);
	}
	dep[1]=1;
	dfs1(1,-1);
	dfs2(1,1);
	scanf("%d",&q);
	while(q--)
	{
		re int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		ans=0;
		for(re int i=l;i<=r;++i)
		{
			for(re int j=i+1;j<=r;++j)
			{
				if(j-i+1>=k)
				{
					re int lca=LCA(i,j);
					ans=max(ans,dep[lca]);
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}
