#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define oF(l,r,i) for(int i=l;i<=r;i++)
#define of(l,r) oF(l,r,i)
#define tF(n,i) oF(1,n,i)
#define tf(n) tF(n,i)
#define nF(i) tF(n,i)
#define nf() nF(i)
#define mF(i) tF(m,i)
#define mf() mF(i)
#define pint pair<int,int>
#define mp make_pair
#define f first
#define s second
#define fin(x) freopen(#x".in","r",stdin)
#define fout(x) freopen(#x".out","w",stdout)
#define file(x) (fin(x),fout(x))
#define Read(x) (fin(x),read())
#define READ(x) (file(x),read())
ll read(){
	int x=0;
	char c=getchar();
	while(c<48||c>57)c=getchar();
	while(c>47&&c<58){
		x=(x<<1)+(x<<3)+(c^48);
		c=getchar();
	}
	return x;
}
void write(ll x){
	if(x>9ll)write(x/10);
	putchar(x%10|48);
}
char gtch(){
	char c=getchar();
	while(c<33)c=getchar();
	return c;
}
//int n=Read(query4);
int n=READ(query);
int h[500005],nxt[1000005],to[1000005],d[500005],idx;
void add(int x,int y){
	to[++idx]=y;
	nxt[idx]=h[x];
	h[x]=idx;
	d[x]++;
}
int fa[500005],dep[500005];
int st[500005],tp;
int Fa[25][500005];
void dfs(int x){
	st[++tp]=x;
	int btp=0;
	while(btp^tp){
		int x=st[++btp];
		dep[x]=dep[fa[x]]+1; 
		Fa[0][x]=fa[x];
		for(int j=1;Fa[j-1][x];j++){
			Fa[j][x]=Fa[j-1][Fa[j-1][x]];
		}
		for(int ep=h[x];ep;ep=nxt[ep]){
			if(to[ep]^fa[x]){
				fa[to[ep]]=x;
				st[++tp]=(to[ep]);
			}
		}
	}
	tp=0;
}
int lca(int x,int y){
	if(dep[x]<dep[y])swap(x,y);
	for(int i=20;~i;i--)if(dep[Fa[i][x]]>=dep[y])x=Fa[i][x];
	if(x==y)return x;
	for(int i=20;~i;i--)if(Fa[i][x]^Fa[i][y])x=Fa[i][x],y=Fa[i][y];
	return fa[x];
}
int B[25][500005];
void pre_LCA(){
	nf()B[0][i]=i;
	for(int j=1;1<<j<=n;j++){
		tf(n-(1<<j)+1){
			B[j][i]=lca(B[j-1][i],B[j-1][i+(1<<j-1)]);
		}
	}
}
int LCA(int x,int y){
	if(y<x)swap(x,y);
	int k=__lg(y-x+1);
	int ans=lca(B[k][x],B[k][y-(1<<k)+1]);
	return ans;
}
signed main(){
	srand(time(0));
	tf(n-1){
		int x=read(),y=read();
		add(x,y);
		add(y,x);
	}
	dfs(1);
	pre_LCA();
	int q=read();
	tF(q,_){
		int l=read(),r=read(),k=read(),ans=dep[LCA(l,l+k-1)];
		if(n*q<=100000000||k==r-l+1)of(l+1,r-k+1)ans=max(ans,dep[LCA(i,i+k-1)]);
		else tf(100000000/q)ans=max(ans,dep[LCA(rand()%(r-k-l)+l+1,rand()%(r-k-l)+l+k)]);
		write(ans),putchar(10);
	}
}
//May all the beauty be blessed

/*
End of every thing
Let me do some intresting
//freopen
*/
