#include<bits/stdc++.h>
using namespace std;
#define N 500005
int n,q;
int tot,head[N];
struct Edge{int next,to;}e[N<<1];
void add_edge(int u,int v){e[++tot]={head[u],v};head[u]=tot;}
int deg[N],dep[N];
int idx,dfn[N],id[N];
int st[21][N],mn[21][N],mx[21][N];
void dfs(int u,int fa)
{
	dep[u]=dep[fa]+1;
	st[0][dfn[u]=++idx]=fa;
	id[dfn[u]]=u;
	mn[0][u]=mx[0][u]=dfn[u];
	for(int i=head[u];i;i=e[i].next)
	{
		int v=e[i].to;if(v==fa) continue;
		dfs(v,u);
	}
}
inline int gmin(int x,int y){return dfn[x]<dfn[y]?x:y;}
int lg[N];
void build_st()
{
	for(int i=2;i<=n;i++)
		lg[i]=lg[i/2]+1;
	for(int i=1;i<=20;i++)
		for(int j=1;j+(1<<i)-1<=n;j++)
		{
			mn[i][j]=min(mn[i-1][j],mn[i-1][j+(1<<i-1)]);
			mx[i][j]=max(mx[i-1][j],mx[i-1][j+(1<<i-1)]);
			st[i][j]=gmin(st[i-1][j],st[i-1][j+(1<<i-1)]);
		}
}
inline 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 len=lg[y-x+1];
	return gmin(st[len][x],st[len][y-(1<<len)+1]);
}
inline int qmin(int x,int y)
{
	int len=lg[y-x+1];
	return min(mn[len][x],mn[len][y-(1<<len)+1]);
}
inline int qmax(int x,int y)
{
	int len=lg[y-x+1];
	return max(mx[len][x],mx[len][y-(1<<len)+1]);
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		add_edge(x,y);add_edge(y,x);
		deg[x]++;deg[y]++;
	}
	bool chain=1;
	for(int i=1;i<=n;i++) chain&=(deg[i]<3);
	scanf("%d",&q);
	dfs(1,0);build_st();
	while(q--)
	{
		int l,r,k;scanf("%d%d%d",&l,&r,&k);
		int ans=0;
		for(int i=l;i+k-1<=r;i++)
		{
			int x=LCA(id[qmin(i,i+k-1)],id[qmax(i,i+k-1)]);
			if(dep[x]>dep[ans]) ans=x;
		}
		printf("%d\n",dep[ans]);
	}
}
