#include<bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=5e5+10;
int n,d[N],dep[N];
vector<int> e[N];
int rt[N],tot=0;
struct S_G{
	struct tr{
		int l,r,s;
	} tr[N*40];
	void update(int &u,int p,int l,int r,int x){
		u=++tot;
		tr[u]=tr[p],tr[u].s++;
		if(l==r) return ;
		int mid=(l+r)>>1;
		if(x<=mid) update(tr[u].l,tr[p].l,l,mid,x);
		else update(tr[u].r,tr[p].r,mid+1,r,x);
	}
	int que(int u,int p,int l,int r,int k){
		if(l==r) return l;
		int mid=(l+r)>>1,s=tr[tr[u].r].s-tr[tr[p].r].s;
		if(k<=s) return que(tr[u].r,tr[p].r,mid+1,r,k);
		return que(tr[u].l,tr[p].l,l,mid,k-s);		
	}
} T;
void dfs(int u,int fa){
	dep[u]=dep[fa]+1;
	for(int v:e[u]){
		if(v==fa) continue;
		dfs(v,u);
	}
}
signed main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	ios::sync_with_stdio(false);
	cin>>n;
	rep(i,2,n){
		int x,y;
		cin>>x>>y;
		e[x].push_back(y),e[y].push_back(x);
		++d[x],++d[y];
	} 
	bool f=(d[1]==1);
	rep(i,2,n) if(d[i]>2){
		f=0;
		break;
	} 
	dfs(1,0);
//	return 0;
//	if(f){
		rep(i,1,n) T.update(rt[i],rt[i-1],1,n,dep[i]);
		int q;
		cin>>q;
		while(q--){
			int l,r,k;
			cin>>l>>r>>k;
			cout<<T.que(rt[r],rt[l-1],1,n,k)<<"\n";
		}
//	}
	return 0;
} 
