#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define mod 1000000007ll
using namespace std;
int read()
{
	int ans=0,fl=1;
	char c=getchar();
	while ((c<'0'||c>'9')&&c!='-') c=getchar();
	if (c=='-')
	{
		c=getchar();
		fl=-1;
	}
	while (c>='0'&&c<='9')
	{
		ans=ans*10+c-48;
		c=getchar();
	}
	return ans*fl;
}
int n,q,dep[500005],fa[500005][20],V[500005];
vector<int> ed[500005];
void dfs(int x,int f)
{
	dep[x]=dep[f]+1;
	V[dep[x]]++;
	fa[x][0]=f;
	for (int i=1;i<20;i++)
	{
		fa[x][i]=fa[fa[x][i-1]][i-1];
	}
	for (int to:ed[x])
	{
		if (to==f) continue;
		dfs(to,x);
	}
	return;
}
int st[20][500005];
int LCA(int x,int y)
{
	if (dep[x]>dep[y]) swap(x,y);
	for (int i=19;i>=0;i--) if (dep[fa[y][i]]>=dep[x]) y=fa[y][i];
	if (x==y) return x;
	for (int i=19;i>=0;i--)
	{
		if (fa[x][i]!=fa[y][i]) x=fa[x][i],y=fa[y][i];
	}
	return fa[x][0];
}
int LG[500005];
int gt(int l,int r)
{
	int D=LG[r-l+1];
	return LCA(st[D][l],st[D][r-(1<<D)+1]);
}
int tr[8000005],ls[8000005],rs[8000005],rt[500005],tot;
int nw(int x)
{
	tr[++tot]=tr[x];
	return tot;
}
void add(int &x,int &y,int l,int r,int v)
{
	x=nw(y);
	tr[x]++;
	if (l==r) return;
	int mid=l+r>>1;
	if (v<=mid)
	{
		add(ls[x],ls[y],l,mid,v);
		rs[x]=rs[y];
	}
	else
	{
		add(rs[x],rs[y],mid+1,r,v);
		ls[x]=ls[y];
	}
	return;
}
int ask(int &x,int &y,int l,int r,int k)
{
	if (l==r) return l;
	int mid=l+r>>1;
	if (tr[rs[x]]-tr[rs[y]]>=k)
	{
		return ask(rs[x],rs[y],mid+1,r,k);
	}
	return ask(ls[x],ls[y],l,mid,k-(tr[rs[x]]-tr[rs[y]]));
}
signed main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n=read();
	for (int i=1;i<n;i++)
	{
		int x=read(),y=read();
		ed[x].emplace_back(y);
		ed[y].emplace_back(x);
	}
	dfs(1,0);
	for (int i=2;i<=n;i++) LG[i]=LG[i>>1]+1;
	for (int i=1;i<=n;i++) st[0][i]=i;
	bool fl=1;
	for (int i=1;i<=n;i++)
	{
		if (V[i]!=1) fl=0;
	}
	if (fl==1)
	{
		for (int i=1;i<=n;i++) add(rt[i],rt[i-1],1,n,dep[i]);
		q=read();
		while (q--)
		{
			int l=read(),r=read(),k=read();
			int ans=ask(rt[r],rt[l-1],1,n,k);
			printf("%d\n",ans);
		}
		return 0;
	}
	for (int i=1;i<20;i++)
	{
		for (int j=1;j+(1<<i)-1<=n;j++)
		{
			st[i][j]=LCA(st[i-1][j],st[i-1][j+(1<<i-1)]);
		}
	}
	q=read();
	while (q--)
	{
		int l=read(),r=read(),k=read(),ans=dep[gt(l,l+k-1)];
		for (int i=l+1;i<=r-k+1;i++) ans=max(ans,dep[gt(i,i+k-1)]);
		printf("%d\n",ans);
	}
	return 0;
}
