#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=5e5+1e2,M=N<<1;
ll n,q;
ll h[N],t[M],nex[M],cnt;
void add(ll u,ll v)
{
	++cnt;
	t[cnt]=v;
	nex[cnt]=h[u];
	h[u]=cnt;
}
ll fa[N][22],dep[N];
void dfs(ll u,ll f)
{
	dep[u]=dep[f]+1,fa[u][0]=f;
	for(ll i=h[u];i;i=nex[i])
	{
		ll j=t[i];
		if(j==f)continue;
		dfs(j,u);
	}
}
void init()
{
	for(ll i=1;i<=__lg(n);i++)
		for(ll j=1;j<=n;j++)
			fa[j][i]=fa[fa[j][i-1]][i-1];
}
ll lca(ll x,ll y)
{
	if(dep[x]<dep[y])swap(x,y);
	ll d=dep[x]-dep[y];
	while(d)
	{
		ll k=__lg(d);
		x=fa[x][k];
		d-=(1<<k);
	}
	if(x==y)return x;
	ll mx_up=__lg(dep[x]);
	for(ll i=mx_up;i>=0;i--)
		if(fa[x][i]!=fa[y][i])
			x=fa[x][i],
			y=fa[y][i];
	return fa[x][0];
}
ll stable[N][22];
void build_ST()
{
	for(ll i=1;i<=n;i++)
		stable[i][0]=i;
	for(ll i=1;i<=__lg(n);i++)
		for(ll j=1;j+(1<<i)-1<=n;j++)
			stable[j][i]=lca(stable[j][i-1],stable[j+(1<<(i-1))][i-1]);
}
ll query_ST(ll l,ll r)
{
	ll lenth=__lg(r-l+1);
	return lca(stable[l][lenth],stable[r-(1<<lenth)+1][lenth]);
}
signed main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%lld",&n);
	for(ll i=1;i<n;i++)
	{
		ll x,y;
		scanf("%lld%lld",&x,&y);
		add(x,y),add(y,x);
	}
	dfs(1,0);
	init();
	ll mxdep=0;
	for(ll i=1;i<=n;i++)
		mxdep=max(mxdep,dep[i]);
	build_ST();
	scanf("%lld",&q);
	while(q--)
	{
		ll l,r,k;
		scanf("%lld%lld%lld",&l,&r,&k);
		ll ans=0;
		for(ll i=l;i+k-1<=r;i++)
			ans=max(ans,dep[query_ST(i,i+k-1)]);
		printf("%lld\n",ans);
	}
}
