#include<bits/stdc++.h>
using namespace std;
const int N=5000+5;
int n,hd[N],to[N*2],nxt[N*2],tot,fa[N],dep[N],dfn[N],top[N],num,siz[N],son[N],ans[N][N],T;
void adde(int u,int v)
{
	++tot,to[tot]=v,nxt[tot]=hd[u],hd[u]=tot;
}
void pf1(int x,int fah)
{
	fa[x]=fah,siz[x]=1,dep[x]=dep[fah]+1;
	for(int i=hd[x],v;i;i=nxt[i])
	{
		v=to[i];
		if(v==fah)	continue;
		pf1(v,x);
		siz[x]+=siz[v];
		if(siz[v]>siz[son[x]])	son[x]=v;
	}
}
void pf2(int x,int Top)
{
	dfn[x]=++num,top[x]=Top;
	if(son[x])	pf2(son[x],Top);
	for(int i=hd[x],v;i;i=nxt[i])
	{
		v=to[i];
		if(v==fa[x]||v==son[x])	continue;
		pf2(v,v);
	}
}
int lca(int u,int v)
{
	while(top[u]!=top[v])
	{
		if(dep[top[u]]<dep[top[v]])	swap(u,v);
		u=fa[top[u]];
	}
	if(dep[u]<dep[v])	return u;
	return v;
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i=1,u,v;i<n;++i)
		scanf("%d%d",&u,&v),adde(u,v),adde(v,u);
	pf1(1,0),pf2(1,1);
	for(int i=1;i<=n;++i)
	{
		ans[i][i]=i;
		for(int j=i+1;j<=n;++j)
			ans[i][j]=lca(ans[i][j-1],j);
	}
	int l,r,k,nans=0;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d%d",&l,&r,&k),nans=0;
		for(int i=l;i<=r-k+1;++i)
			nans=max(nans,dep[ans[i][i+k-1]]);
		printf("%d\n",nans);
	}
	return 0;
}
