#include<bits/stdc++.h>
#define ll long long
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=y;i>=x;i--)
#define file(NAME)\
	freopen(NAME".in","r",stdin),\
	freopen(NAME".out","w",stdout)
#define lian(x,y) e[++em]=y,nx[em]=ls[x],ls[x]=em
using namespace std;
const int N=5e5+5,M=N*2,K=21,P=998244353;
struct Node {int l,r,k,id;}a[N];
int n,u,v,q,o,ans[N];
int e[M],ls[N],nx[M],em;
int fa[N][K],dep[N];
void mk(int x)
{
	dep[x]=dep[fa[x][0]]+1;
	rep(i,1,K-1) fa[x][i]=fa[fa[x][i-1]][i-1];
	for(int i=ls[x];i;i=nx[i])
		if(fa[x][0]!=e[i]) fa[e[i]][0]=x,mk(e[i]);
}
int lca(int x,int y)
{
	if(x==0||y==0) return x|y;
	if(dep[x]<dep[y]) swap(x,y);
	int d=dep[x]-dep[y];
	for(int i=0;d;d>>=1,i++)
		if(d&1) x=fa[x][i];
	if(x==y) return x;
	per(i,0,K-1) if(fa[x][i]!=fa[y][i]) x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}
#define X 1,n,1
#define Y int x,int y,int p
#define D int mid=(x+y)/2
#define L x,mid,p*2
#define R mid+1,y,p*2+1
int t[N*5];
int seg(Y)
{
	if(x==y) return t[p]=x;
	D;return t[p]=lca(seg(L),seg(R));
}
int fnd(Y,int l,int r)
{
	if(x>r||y<l) return 0;
	if(l<=x&&y<=r) return t[p];
	D;return lca(fnd(L,l,r),fnd(R,l,r));
}

#define vec vector<Node>
#define pb push_back
struct Seg{int le,ri,s,len;}tt[N*5],zr;
int w[N];
Seg mer(Seg x,Seg y)
{
	if(x.len==-1) return y;
	if(y.len==-1) return x;
	Seg nw;
	nw.len=x.len+y.len;
	if(x.le==x.len) nw.le=x.le+y.le;
	else nw.le=x.le;
	if(y.ri==y.len) nw.ri=x.ri+y.ri;
	else nw.ri=y.ri;
	nw.s=max(max(x.s,y.s),x.ri+y.le);
	return nw;
}
void cng(Y,int w,int v)
{
	if(x==y) {tt[p].le=tt[p].ri=tt[p].s=v;return;}
	D;
	if(mid>=w) cng(L,w,v);
	else cng(R,w,v);
	tt[p]=mer(tt[p*2],tt[p*2+1]);
}
Seg fd(Y,int l,int r)
{
	if(x>r||y<l) return zr;
	if(l<=x&&y<=r) return tt[p];
	D;return mer(fd(L,l,r),fd(R,l,r));
}
vec vv;
void dvd(int x,int y,vec c)
{
	if(c.empty()) return;
	if(x==y)
	{
		for(auto i:c) ans[i.id]=x;
		return;
	}
	D;
	rep(i,mid+1,y) cng(X,w[i],1);
	vec c1,c2;
	for(auto i:c)
	{
		if(fd(X,i.l,i.r).s<i.k) c1.pb(i);
		else c2.pb(i);
	}
	dvd(x,mid,c1);
	rep(i,mid+1,y) cng(X,w[i],0);
	dvd(mid+1,y,c2);
}
int main()
{
	file("query");
	scanf("%d",&n);
	rep(i,1,n-1) scanf("%d%d",&u,&v),lian(u,v),lian(v,u);
	scanf("%d",&q);
	rep(i,1,q)
		scanf("%d%d%d",&a[i].l,&a[i].r,&a[i].k),a[i].id=i,
		o|=(a[i].k!=a[i].r-a[i].l+1);
	fa[1][0]=1,mk(1);
	if(n<=5000)
	{
		int f[n+5][n+5],ans;
		rep(i,1,n)
		{
			f[i][i]=i;
			rep(j,i+1,n) f[i][j]=lca(f[i][j-1],j);
		}
		rep(i,1,q)
		{
			ans=0;
			rep(j,a[i].l,a[i].r-a[i].k+1)
				ans=max(ans,dep[f[j][j+a[i].k-1]]);
			printf("%d\n",ans);
		}
		return 0;
	}
	if(o==0)
	{
		seg(X);
		rep(i,1,q) printf("%d\n",dep[fnd(X,a[i].l,a[i].r)]);
		return 0;
	}
	rep(i,1,n) w[dep[i]]=i;
	zr.len=-1;
	rep(i,1,n*5) tt[i].len=1;
	rep(i,1,q) vv.pb(a[i]);
	dvd(1,n,vv);
	rep(i,1,q) printf("%d\n",ans[i]);
	return 0;
}
