#include<bits/stdc++.h>
using namespace std;
const int MAXN=5e5+10;
int n,q;
struct edges{
	int u,v,nxt;
}e[MAXN<<1];
int head[MAXN],tot;
int deep[MAXN],maxn[MAXN];
void add(int u,int v)
{
	e[++tot].v=v;
	e[tot].nxt=head[u];
	head[u]=tot;
	return ;
}
void dfs(int u,int father)
{
	for(int i=head[u];i;i=e[i].nxt)
	{
		int v=e[i].v;
		deep[v]=deep[u]+1;
		if(v!=father) dfs(v,u);
	}
}
void build(int p,int l,int r)
{
	if(l==r)
	{
		maxn[p]=deep[l];
		return ;
	}
	int mid=(l+r)>>1;
	build(p<<1,l,mid);
	build(p<<1|1,mid+1,r);
	maxn[p]=min(maxn[p<<1],maxn[p<<1|1]);
	return ; 
}
int ask(int p,int l,int r,int L,int R)
{
	if(L<=l && r<=R)
	{
		return maxn[p];
	}
	int mid=(l+r)>>1;
	int ans=0;
	if(L<=mid) ans=min(ans,ask(p<<1,l,mid,L,R));
	if(R>mid) ans=min(ans,ask(p<<1|1,mid+1,r,L,R));
	return ans;
}
signed main()
{
	freopen("query3.in","r",stdin);
	freopen("query.out","w",stdout); 
	deep[1]=1;
	build(1,1,n);
	scanf("%d",&n);
	for(int i=1,u,v;i<n;i++)
	{
		scanf("%d %d",&u,&v);
		add(u,v),add(v,u); 
	}
	scanf("%d",&q);
	while(q--)
	{
		int l,r,k;
		scanf("%d %d %d",&l,&r,&k);
		ans=ask(1,1,n,i,i+k-1);
		printf("%d",ans);
	}
	return 0;
} 
