#include<bits/stdc++.h>
using namespace std;
struct node{
	int to,nex;
}e[1000005];
int head[1000005],tot,dep[500005],val[500005],dep2[500005],f[500005],tong[500005];
queue<int> qu,qw;
void add(int u,int v){
	tot++;
	e[tot].to=v;
	e[tot].nex=head[u];
	head[u]=tot;
}
void dfs(){
	int u=1;
	qu.push(u);
	val[u]=1;
	while(!qu.empty()){
		u=qu.front();
		for(int i=head[u];i;i=e[i].nex){
			if(val[e[i].to])
			  continue;
			dep[e[i].to]=dep[u]+1;
			qu.push(e[i].to);
			val[e[i].to]=1;
			f[e[i].to]=u;
		}
		qu.pop();
	}
}
void solve(int l,int r){
	memset(tong,0,sizeof(tong));
	for(int i=l;i<=r;i++){
		tong[i]++;
		if(tong[i]==r-l+1){
			cout<<dep[i]<<endl;
			return ;
		}
		qw.push(i);
	}
	while(1){
		qw.push(f[qw.front()]);
		tong[f[qw.front()]]++;
		if(tong[f[qw.front()]]==r-l+1){
			cout<<dep[f[qw.front()]]<<endl;
			return ;
		}
		qw.pop();
	}
}
int main(){
	freopen("query.in","r",stdin); 
	freopen("query.out","w",stdout); 
	int n,q;
	cin>>n;
	f[1]=1;
	for(int i=1;i<=n-1;i++){
		int x,y;
		cin>>x>>y;
		add(x,y);
		add(y,x);
	}
	dfs();
	cin>>q;
	for(int i=1;i<=q;i++){
		int l,r,k;
		cin>>l>>r>>k;
		if(r-l+1==k){
			solve(l,r);
			continue;
		}
		for(int j=l;j<=r;j++){
			dep2[j]=dep[j];
		}
		sort(dep+l+1,dep+r+1);
		cout<<dep[r-k+1]<<endl;
	}
}
