#include<bits/stdc++.h>
using namespace std;
const int N=5e5+10;
int n,dp[N],fa[N],sz[N],son[N],top[N],q;
vector<int> a[N];
void dfs1(int u,int fat,int dep){
	dp[u]=dep;sz[u]=1;fa[u]=fat;
	for(int i=0;i<a[u].size();i++){
		if(a[u][i]==fat) continue;
		dfs1(a[u][i],u,dep+1);
		if(!son[u]) son[u]=a[u][i];
		else if(sz[a[u][i]]>sz[son[u]]) son[u]=a[u][i];
		sz[u]+=sz[a[u][i]];
	}
	return;
}
void dfs2(int u,int to){
	top[u]=to;
	if(son[u]) dfs2(son[u],u);
	for(int i=0;i<a[u].size();i++){
		if(a[u][i]==fa[u]||a[u][i]==son[u]) continue;
		dfs2(a[u][i],a[u][i]);
	}
	return;
}
int lca(int x,int y){
	while(top[x]!=top[y]){
		if(dp[top[x]]<dp[top[y]]) swap(x,y);
		x=fa[top[x]];
	} 
	if(dp[top[x]]>dp[top[y]]) swap(x,y);
	return x;
}
int vktl(int x,int y){
	int h=x;
	for(int i=x+1;i<=y;i++) h=lca(h,i);
	return dp[h];
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin>>n;
	int x,y;
	for(int i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		a[x].push_back(y);
		a[y].push_back(x);
	}
	dfs1(1,1,1);
	dfs2(1,1);
	cin>>q;
	int z;
	while(q--){
		scanf("%d%d%d",&x,&y,&z);
		while(y-x>z){
			if(dp[vktl(x+1,y)]>=dp[vktl(x,y-1)]) x++;
			else y--;
		} 
		int h=x;
		for(int i=x+1;i<=y;i++) h=lca(h,i);
		printf("%d\n",dp[h]);
	}
	return 0;
}

