#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define MP make_pair
#define eb emplace_back 
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
typedef long long ll;
using namespace std;

int read(){
	int s=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')f^=(c=='-'),c=getchar();
	while(c>='0'&&c<='9')s=s*10+c-'0',c=getchar();
	return f?s:-s;
}

const int N=500005;
int n,q,dfn[N<<1],Dfn,dep[N<<1],st[N<<1][20],in[N],out[N],deg[N],mn[N][20],mx[N][20];
vector<int>vec[N];
vector<int>e[N];
void dfs(int u,int fat){
	dep[u]=dep[fat]+1;
	in[u]=++Dfn;
	st[Dfn][0]=dep[u];
	for(int v:e[u])if(v^fat){
		dfs(v,u);
		st[++Dfn][0]=dep[u];
	}
	out[u]=Dfn;
	vec[dep[u]].eb(u);
}
bool chk(){
	rep(i,2,n)if(deg[i]>2)return 0;
	return deg[1]==1;
}
int ans[N];
struct query{
	int l,r,k,id;
}que[N];
struct node{
	int lmx,rmx,mx,len;
};
node operator+(node x,node y){
	node res;
	if(x.lmx==x.len)res.lmx=x.len+y.lmx;
	else res.lmx=x.lmx;
	if(y.rmx==y.len)res.rmx=y.len+x.rmx;
	else res.rmx=y.rmx;
	res.mx=max({x.mx,y.mx,x.rmx+y.lmx});
	res.len=x.len+y.len;
	return res;
}
struct SGT{
	node s[N<<2];
	void update(int l,int r,int p,int v,int t){
		if(l==r)return s[t]=node{v,v,v,1},void();
		int mid=(l+r)>>1;
		if(mid>=p)update(l,mid,p,v,t<<1);
		else update(mid+1,r,p,v,t<<1|1);
		s[t]=s[t<<1]+s[t<<1|1];
	}
	node query(int l,int r,int L,int R,int t){
		if(L<=l&&r<=R)return s[t];
		int mid=(l+r)>>1;
		if(mid>=L&&mid<R)return query(l,mid,L,R,t<<1)+query(mid+1,r,L,R,t<<1|1);
		if(mid>=L)return query(l,mid,L,R,t<<1);
		return query(mid+1,r,L,R,t<<1|1);
	}
}sgt;
void solve(int l,int r,vector<query>&V){
	if(V.empty())return;
	if(l==r){
		for(auto x:V)ans[x.id]=l;
		return;
	}
	int mid=(l+r)>>1;
	rep(i,mid+1,r)sgt.update(1,n,vec[i][0],1,1);
	vector<query>Vl,Vr;
	for(auto it:V){
		if(sgt.query(1,n,it.l,it.r,1).mx>=it.k)Vr.eb(it);
		else Vl.eb(it);
	} 
	solve(l,mid,Vl);
	rep(i,mid+1,r)sgt.update(1,n,vec[i][0],0,1);
	solve(mid+1,r,Vr);
}
void Sub(){
	vector<query>V;
	rep(i,1,q){
		int l=read(),r=read(),k=read();
		V.eb(query{l,r,k,i});
	} 
	solve(1,n,V);
	rep(i,1,q)printf("%d\n",ans[i]);
	exit(0);
}
int qmin(int l,int r){
	int k=__lg(r-l+1);
	return min(mn[l][k],mn[r-(1<<k)+1][k]);
}
int qmax(int l,int r){
	int k=__lg(r-l+1);
	return max(mx[l][k],mx[r-(1<<k)+1][k]);
}
int qry(int l,int r){
	if(l>r)swap(l,r);
	int mn=qmin(l,r),mx=qmax(l,r);
	l=mn,r=mx;
	int k=__lg(r-l+1);
	return min(st[l][k],st[r-(1<<k)+1][k]);
}
void Sub2(){
	rep(i,1,q){
		int l=read(),r=read(),k=read(),ans=0;
		rep(j,l,r-k+1)ans=max(ans,qry(j,j+k-1));
		printf("%d\n",ans);
	}
}

signed main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n=read();
	rep(i,1,n-1){
		int u=read(),v=read();
		e[u].eb(v),e[v].eb(u);
		deg[u]++,deg[v]++;
	}
	dfs(1,0);
	rep(j,1,19)rep(i,1,n+n-(1<<j))st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]);
	rep(i,1,n){
		mn[i][0]=in[i],mx[i][0]=out[i];
	}
	rep(j,1,19){
		rep(i,1,n)mx[i][j]=max(mx[i][j-1],mx[i+(1<<(j-1))][j-1]),mn[i][j]=min(mn[i][j-1],mn[i+(1<<(j-1))][j-1]);
	}
	q=read();
	if(chk())Sub();
	else Sub2();
	return 0;
}
