#include<bits/stdc++.h>
#include<cstdio>
#define ll int
#define N 1000020

using namespace std;

inline ll read()
{
	ll x=0,f=1;
	char ch=getchar();
	while(ch>'9'||ch<'0')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*f; 
} 

void write(ll x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>=10)write(x/10);
	putchar(x%10+'0');
}

struct pp
{
	ll nex,to;
}
edge[N];

ll n,Q; 
ll head[N],cnt=1;
ll na,nb,k;
ll dep[N],f[N][20];
ll lca[N][20];
ll depmax[N][20];

inline void add(ll from,ll to)
{
	edge[cnt].to=to;
	edge[cnt].nex=head[from];
	head[from]=cnt++;
}

inline void dfs(ll x,ll fa,ll de)
{
	dep[x]=de;
	f[x][0]=fa;
	ll to=log2(dep[x]);
	for(ll i=1;i<=to;i++)
	{
		f[x][i]=f[f[x][i-1]][i-1];
	}
	for(ll i=head[x];i;i=edge[i].nex)
	{
		ll v=edge[i].to;
		if(v==fa)continue;
		dfs(v,x,de+1);
	}
}

inline ll getlca(ll x,ll y)
{
	if(dep[x]<dep[y])swap(x,y);
	while(dep[x]>dep[y])
	{
		x=f[x][(ll)log2(dep[x]-dep[y])];
	}
	if(x==y)return x;
	for(ll i=log2(dep[x]);i>=0;i--)
	{
		if(f[x][i]!=f[y][i])
		{
			x=f[x][i];
			y=f[y][i];
		}
	}
	return f[x][0];
}

inline void init()
{
	n=read();
	for(ll i=1;i<n;i++)
	{
		na=read();
		nb=read();
		add(na,nb);
		add(nb,na);
	}
	dfs(1,1,1);
	for(ll i=1;i<=n;i++)
	{
		lca[i][0]=i;
		depmax[i][0]=dep[i];
	}
	for(ll j=1;(1<<j)<=n;j++)
	{
		for(ll i=1;i+(1<<j)-1<=n;i++)
		{
			lca[i][j]=getlca(lca[i][j-1],lca[i+(1<<(j-1))][j-1]);
		}
	}
}

inline ll getans(ll x,ll y)
{
	ll nk=log2(y-x+1);
	ll ok=getlca(lca[x][nk],lca[y-(1<<nk)+1][nk]);
	return dep[ok];
}

inline void work()
{
	Q=read();
	while(Q--)
	{
		ll ans=-1;
		na=read();
		nb=read();
		k=read();
		ll to=nb-k+1;
		for(ll i=na;i<=to;i++)
		{
			ans=max(ans,getans(i,i+k-1));
		}
		write(ans);
		putchar('\n');
	}
}

int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	init();
	work();
	return 0;
}
