#include<bits/stdc++.h>
const int N=2e6+10,LOGN=log2(N)+1;
int de[N],mn[N],mx[N],E,dep[N];
std::vector<int> to[N];
void dfs(int u,int fa=0){
	dep[u]=dep[fa]+1;
	de[++E]=dep[u],mx[u]=mn[u]=E;
	for(int v:to[u]){
		if(v==fa) continue;
		dfs(v,u);
		de[++E]=dep[u],mx[u]=E;
	}
}
int min[N][LOGN],max[N][LOGN];
int st[N][LOGN],lg[N];
int getmin(int l,int r){
	int k=lg[r-l+1];
	return std::min(min[l][k],min[r-(1<<k)+1][k]);
}
int getmax(int l,int r){
	int k=lg[r-l+1];
	return std::max(max[l][k],max[r-(1<<k)+1][k]);
}
int LCA(int l,int r){
	int k=lg[r-l+1];
	return std::min(st[l][k],st[r-(1<<k)+1][k]);
}
int solve(int l,int r){
	return LCA(getmin(l,r),getmax(l,r));
}
std::mt19937 myrand(time(0));
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	int n;scanf("%d",&n);
	for(int i=1,u,v;i<n;i++){
		scanf("%d%d",&u,&v);
		to[u].push_back(v),to[v].push_back(u);
	}
	dfs(1);
	lg[0]=-1;
	for(int i=1;i<=E;i++) st[i][0]=de[i],lg[i]=lg[i/2]+1;
	for(int i=1;i<=n;i++) min[i][0]=mn[i],max[i][0]=mx[i];
	for(int j=1;(1<<j)<=n;j++){
		for(int i=1;i+(1<<j)-1<=n;i++){
			min[i][j]=std::min(min[i][j-1],min[i+(1<<j-1)][j-1]);
			max[i][j]=std::max(max[i][j-1],max[i+(1<<j-1)][j-1]);
		}
	}
	for(int j=1;(1<<j)<=E;j++){
		for(int i=1;i+(1<<j)-1<=E;i++){
			st[i][j]=std::min(st[i][j-1],st[i+(1<<j-1)][j-1]);
		}
	}
	int q;scanf("%d",&q);
	int qt=1e7/q;
	while(q--){
		int l,r,k;scanf("%d%d%d",&l,&r,&k);
		int ans=std::max(solve(l,l+k-1),solve(r-k+1,r));
		if(r-l-k>0){
			for(int i=1;i<=qt;i++){
				int p=myrand()%(r-l-k)+l+1;
				ans=std::max(ans,solve(p,p+k-1));
			}
		}
		printf("%d\n",ans);
	}
}
