#include<bits/stdc++.h>
#define ls (k<<1)
#define rs (k<<1|1)
using namespace std;
typedef int ll;
ll n,q,h[500001],siz[500001],son[500001],dep[500001],top[500001],fa[500001],cnt,ans;
bool flag;
struct node
{
	ll ne,to;
}e[1000001];
inline ll read()
{
	ll s=0,f=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) s=(s<<3)+(s<<1)+(ch^48);
	return f?-s:s;
}
inline void add(ll u,ll v)
{
	e[++cnt].ne=h[u];
	e[cnt].to=v;
	h[u]=cnt;
}
void dfs1(ll x,ll f)
{
	fa[x]=f;
	dep[x]=dep[f]+1;
	flag|=(dep[x]==n);
	siz[x]=1;
	for(ll i=h[x];i;i=e[i].ne)
	{
		ll y=e[i].to;
		if(y==f) continue;
		dfs1(y,x);
		siz[x]+=siz[y];
		if(siz[y]>siz[son[x]]) son[x]=y;
	}
}
void dfs2(ll x,ll tp)
{
	top[x]=tp;
	if(!son[x]) return;
	dfs2(son[x],tp);
	for(ll i=h[x];i;i=e[i].ne)
	{
		ll y=e[i].to;
		if(y==fa[x] || y==son[x]) continue;
		dfs2(y,y);
	}
}
inline ll lca(ll x,ll 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 x;
	return y;
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n=read();
	for(ll i=1;i<n;i++)
	{
		ll u=read(),v=read();
		add(u,v);
		add(v,u);
	}
	dfs1(1,0);
	dfs2(1,1);
	q=read();
	while(q--)
	{
		ll l=read(),r=read(),k=read();
		ans=0;
		for(ll i=l;i+k-1<=r;i++)
		{
			ll p=i;
			for(ll j=i;j<=i+k-1;j++) p=lca(p,j);
			ans=max(ans,dep[p]);
		}
		cout<<ans<<"\n";
	}
	return 0;
}
