#include<bits/stdc++.h>
using namespace std;
const int MAXN=5e5+5;
int n,m,fa[MAXN],dep[MAXN],dfn[MAXN],rnk[MAXN],cnt;
int f[21][MAXN],g[21][MAXN],h[21][MAXN],lg2[MAXN];
vector<int> ve[MAXN];
int get(int x,int y)
{
	return dep[x]<dep[y]?x:y;
}
void dfs(int o,int pa)
{
	fa[o]=pa;dep[o]=dep[pa]+1;dfn[o]=++cnt;rnk[cnt]=o;
	f[0][cnt]=o;g[0][o]=cnt;h[0][o]=cnt;
	for(auto u:ve[o])
	{
		if(u==pa)continue;
		dfs(u,o);
	}
}
void init()
{
	for(int i=2;i<=n;i++)lg2[i]=lg2[i>>1]+1;
	for(int i=1;(1<<i)<=n;i++)
		for(int j=1;j+(1<<i)-1<=n;j++)
			f[i][j]=get(f[i-1][j],f[i-1][j+(1<<i-1)]),
			g[i][j]=min(g[i-1][j],g[i-1][j+(1<<i-1)]),
			h[i][j]=max(h[i-1][j],h[i-1][j+(1<<i-1)]);
}
int lca(int x,int y)
{
	if(x==y)return x;
	x=dfn[x],y=dfn[y];
	if(x>y)swap(x,y);x++;
	int d=lg2[y-x+1];
	return fa[get(f[d][x],f[d][y-(1<<d)+1])];
}
int getmx(int l,int r)
{
	int d=lg2[r-l+1];
	return rnk[max(h[d][l],h[d][r-(1<<d)+1])];
}
int getmn(int l,int r)
{
	int d=lg2[r-l+1];
	return rnk[min(g[d][l],g[d][r-(1<<d)+1])];
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int u,v;scanf("%d%d",&u,&v);
		ve[u].push_back(v);
		ve[v].push_back(u);
	}
	dfs(1,1);
	init();
	cin>>m;
	for(int i=1;i<=m;i++)
	{
		int l,r,k,ans=0;scanf("%d%d%d",&l,&r,&k);
		for(int j=l;j<=r-k+1;j++)
		{
			int lc=lca(getmx(j,j+k-1),getmn(j,j+k-1));
			ans=max(ans,dep[lc]);
		}
		printf("%d\n",ans);
	}
	return 0;
}
