#include<bits/stdc++.h>
using namespace std;

#define int long long
#define siz(x) ((int)(x).size()) 
#define me(x,v) memset(x,v,sizeof(x))
#define L(i,l,r) for(int i=(l);i<=(r);i++)
#define R(i,r,l) for(int i=(r);i>=(l);i--)
#define ve(x) vector<x>
#define pa(x,y) pair<x,y>
#define x first
#define y second

char gc(){
	return getchar();
}
void pc(char c){
	putchar(c);
}
void el(){
	pc('\n');
}
int qread(){
	int res=0;
	bool sgn=0;
	char c=gc();
	while(c<'0'||c>'9'){
		sgn|=(c=='-');
		c=gc();
	}
	while(c>='0'&&c<='9'){
		res=res*10+c-'0';
		c=gc();
	}
	return sgn?-res:res;
}

constexpr int N=114514;
struct Q{
	int l,r,k;
};
struct E{
	int v,next;
};

int head[N];
E edge[2*N];
int esize;

void add(int u,int v){
	edge[++esize]={v,head[u]};
	head[u]=esize;
}

int lg[N];

int fj[N][23];
int dep[N],fa[N];
void dfs(int u){
	dep[u]=dep[fa[u]]+1;
	fj[u][0]=fa[u];
	L(i,1,lg[dep[u]]){
		fj[u][i]=fj[fj[u][i-1]][i-1];
	}
	for(int i=head[u];i;i=edge[i].next){
		int v=edge[i].v;
		if(v==fa[u]){
			continue;
		}
		fa[v]=u;
		dfs(v);
	}
}

int lca(int u,int v){
	assert(u);
	assert(v);
	if(dep[u]<dep[v]){
		swap(u,v);
	}
	while(dep[u]!=dep[v]){
		u=fj[u][lg[dep[u]-dep[v]]];
	}
	if(u==v){
		return u;
	}
	R(i,lg[dep[u]],0){
		if(fj[u][i]!=fj[v][i]){
			u=fj[u][i];
			v=fj[v][i];
		}
	}
	return fa[u];
}

ve(Q) qry; 

int n;
bool vis[N];
bool check(){
	L(i,1,n){
		if(!vis[dep[i]]){
			vis[dep[i]]=1;
		}else{
			return 0;
		}
	}
	return 1;
}

int ans[N];

int lj[N][23];
void task1(){
	L(i,1,n){
		lj[i][0]=i;
	}	
	
	L(j,1,lg[n]){
		L(i,1,n){
			if(j>lg[n-i+1]){
				continue;
			}
			lj[i][j]=lca(lj[i][j-1],lj[i+(1<<(j-1))][j-1]);
//			printf("lj[%lld,%lld]=%lld\n",i,i+(1<<j)-1,lj[i][j]);
		}
	}
	
	auto query=[&](int l,int r)->int{
		int g=lg[r-l+1];
		int x=lj[l][g],y=lj[r-(1<<g)+1][g];	
		int a=lca(x,y);
		return dep[a];
	};
	
	L(i,0,siz(qry)-1){
		int l=qry[i].l,r=qry[i].r,k=qry[i].k;
		int res=0;
		L(u,l+k-1,r){
			res=max(res,query(u-k+1,u));
		}
		ans[i]=res;
	} 
}

void task2(){
	L(i,1,n){
		lj[i][0]=dep[i];
	}	
	
	L(j,1,lg[n]){
		L(i,1,n){
			if(j>lg[n-i+1]){
				continue;
			}
			lj[i][j]=min(lj[i][j-1],lj[i+(1<<(j-1))][j-1]);
		}
	}
	
	auto query=[&](int l,int r)->int{
		int g=lg[r-l+1];
		int x=lj[l][g],y=lj[r-(1<<g)+1][g];	
		int a=min(x,y);
		return a;
	};
	
	L(i,0,siz(qry)-1){
		int l=qry[i].l,r=qry[i].r,k=qry[i].k;
		int res=0;
		L(u,l+k-1,r){
			res=max(res,query(u-k+1,u));
		}
		ans[i]=res;
	} 
}

signed main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	
	n=qread();
	L(i,2,n){
		int u=qread(),v=qread();
		add(u,v),add(v,u);
	}
	
	L(i,2,n){
		lg[i]=lg[i>>1]+1;
	}
	
	dfs(1); 
		
	int q=qread();
	while(q--){
		int l=qread(),r=qread(),k=qread();
		qry.push_back({l,r,k});
	}
	
	if(check()){
		task2();
	}else{
		task1();
	}
	
	L(i,0,siz(qry)-1){
		printf("%lld\n",ans[i]);
	}
	return 0;
} 
