#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define fre(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
using namespace std;
const int N=5e5+10;
bool st;
int n,q,dep[N],t[N*6],fa[N][20];
vector<int> g[N];
bool ed;
void read(int &x)
{
	x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
}
void write(int x)
{
	if(x<10)putchar(x+'0');
	else write(x/10),putchar(x%10+'0');
}
void dfs(int x)
{
	for(int i=1;i<20;i++)fa[x][i]=fa[fa[x][i-1]][i-1];
	for(int v:g[x])if(v!=fa[x][0])dep[v]=dep[x]+1,fa[v][0]=x,dfs(v);
}
int lca(int x,int y)
{
	if(dep[x]>dep[y])swap(x,y);
	int dlt=dep[y]-dep[x];
	for(int i=19;i>=0;i--)if((dlt>>i)&1)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];
}
void build(int o,int l,int r)
{
	if(l==r)
	{
		t[o]=lca(l,l+1);
		return;
	}
	int mid=(l+r)>>1;
	build(o*2,l,mid);
	build(o*2+1,mid+1,r);
	t[o]=lca(t[o*2],t[o*2+1]);
}
int query(int o,int l,int r,int x,int y)
{
	if(r<x||y<l)return -1;
	if(x<=l&&r<=y)return t[o];
	int mid=(l+r)>>1;
	int sl=query(o*2,l,mid,x,y);
	int sr=query(o*2+1,mid+1,r,x,y);
	if(min(sl,sr)==-1)return max(sl,sr);
	return lca(sl,sr);
}
int main()
{
	fre("query");
	read(n);
	for(int i=1;i<n;i++)
	{
		int x,y;
		read(x),read(y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dep[1]=1,dfs(1);
	build(1,1,n-1);
	read(q);
	while(q--)
	{
		int l,r,k,ans=1;
		read(l),read(r),read(k);
		for(int i=l,j=l+k-1;j<=r;i++,j++)ans=max(ans,(i==j?dep[i]:dep[query(1,1,n-1,i,j-1)]));
		write(ans),putchar('\n');
	}
}