#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
inline void read(int &x){
	char ch=getchar();
	int q=1;x=0;
	while(ch<'0'||ch>'9'){
		if(ch=='-'){
			q=-1;
		}
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+(ch-'0');
		ch=getchar();
	}
	x=x*q;
	return;
}
struct node{
	int l,r,val,pos;
	node operator + (const node& x)const{
		if(x.val<val){
			return {l,x.r,x.val,x.pos};
		}else{
			return {l,x.r,val,pos};
		}
	}
}arr[N];
vector<int>e[N];
int d[N];
int n,q;
void get_deep(int x,int fa){
	for(auto i:e[x]){
		if(i!=fa){
			d[i]=d[x]+1;
			get_deep(i,x);
			return;
		}
	}
}
void build(int l,int r,int p){
	if(l==r){
		arr[p].l=arr[p].r=l,arr[p].pos=l,arr[p].val=d[l];
		return;
	}
	int mid=(l+r)>>1;
	build(l,mid,p<<1);
	build(mid+1,r,p<<1|1);
	arr[p]=arr[p<<1]+arr[p<<1|1];
	return;
}
node get_ans(int l,int r,int tl,int tr,int p){
	if(tl<=l&&tr>=r){
		return arr[p];
	}
	node res;int mid=(l+r)>>1;
	res.val=1e9;
	if(tl<=mid)	res=res+get_ans(l,mid,tl,tr,p<<1);
	if(tr>mid)	res=res+get_ans(mid+1,r,tl,tr,p<<1|1);
	return res;
}
int work(int l,int r,int k){
	if(l>r){
		return 0;
	}
	node mid=get_ans(1,n,l,r,1);
	if(mid.pos-l>=k&&r-mid.pos>=k){
		return max(work(l,mid.pos-1,k),work(mid.pos+1,r,k));
	}
	if(mid.pos-l>=k){
		return work(l,mid.pos-1,k);
	}
	if(r-mid.pos>=k){
		return work(mid.pos+1,r,k);
	}
	return mid.val;
}
signed main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	read(n);
	int u,v;
	for(int i=1;i<n;i++){
		read(u),read(v);
		
		e[u].push_back(v);
		
		e[v].push_back(u);
	}
	d[1]=0;
	int l,r,k;
	get_deep(1,0);
	read(q);
	build(1,n,1);
	for(int i=1;i<=q;i++){
		read(l),read(r),read(k);
		cout<<work(l,r,k)+1<<"\n";
	}
	return 0;
}
