#include<vector>
#include<cstdio>
#define fr(i,a,b) for(int i=a;i<=b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
constexpr int N=5e5;
int n,q;
vector<int>E[N+5];
int cntd;
int dep[N+5];
int dfn[N+5];
int fa[N+5][25];
void dfs(int x,int f)
{
	fa[x][0]=f;
	dep[x]=dep[f]+1;
	dfn[x]=++cntd;
	for(auto v:E[x])
	{
		if(v==f) continue;
		dfs(v,x);
	}
}
int getlca(int u,int v)
{
	if(dep[u]<dep[v]) swap(u,v);
	fd(k,20,0)
	{
		if(dep[fa[u][k]]>=dep[v])
		{
			u=fa[u][k];
		}
	}
	if(u==v) return u;
	fd(k,20,0)
	{
		if(fa[u][k]!=fa[v][k])
		{
			u=fa[u][k];
			v=fa[v][k];
		}
	}
	return fa[u][0];
}
int f[N+5][25];
int g[N+5][25];
int Log[N+5];
void init()
{
	fr(i,2,n) Log[i]=Log[i/2]+1;
	fr(i,1,n) f[i][0]=i;
	fr(i,1,n) g[i][0]=i;
	fr(k,1,20)
	{
		fr(i,1,n)
		{
			fa[i][k]=fa[fa[i][k-1]][k-1];
		}
	}
	fr(k,1,20)
	{
		for(int i=1;i+(1<<k)-1<=n;++i)
		{
			if(dfn[f[i][k-1]]<dfn[f[i+(1<<(k-1))][k-1]])
			{
				f[i][k]=f[i][k-1];
			}
			else
			{
				f[i][k]=f[i+(1<<(k-1))][k-1];
			}
		}
	}
	fr(k,1,20)
	{
		for(int i=1;i+(1<<k)-1<=n;++i)
		{
			if(dfn[g[i][k-1]]>dfn[g[i+(1<<(k-1))][k-1]])
			{
				g[i][k]=g[i][k-1];
			}
			else
			{
				g[i][k]=g[i+(1<<(k-1))][k-1];
			}
		}
	}
}
int getmin(int l,int r)
{
	int k=Log[r-l+1];
	if(dfn[f[l][k]]<dfn[f[r-(1<<k)+1][k]])
	{
		return f[l][k];
	}
	else
	{
		return f[r-(1<<k)+1][k];
	}
}
int getmax(int l,int r)
{
	int k=Log[r-l+1];
	if(dfn[g[l][k]]>dfn[g[r-(1<<k)+1][k]])
	{
		return g[l][k];
	}
	else
	{
		return g[r-(1<<k)+1][k];
	}
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	fr(i,2,n)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	dfs(1,0);
	init();
	scanf("%d",&q);
	fr(i,1,q)
	{
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		int ans=0;
		fr(i,l,r-k+1)
		{
			int minx=getmin(i,i+k-1);
			int maxx=getmax(i,i+k-1);
			ans=max(ans,dep[getlca(minx,maxx)]);
		}
		printf("%d\n",ans);
	}
	return 0;
}