#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

char buf[1<<20],*p1,*p2;
#define getchar() (p1==p2 && (p2=((p1=buf)+fread(buf,1,1<<20,stdin)),p1==p2)?EOF:*p1++);
void read(int &x){
	x=0;
	int f=1;
	char c=getchar();
	while(!('0'<=c && c<='9')){
		if(c=='-'){
			f=-1;
		}
		c=getchar();
	}
	while('0'<=c && c<='9'){
		x=(x<<3)+(x<<1)+(c^48);
		c=getchar();
	}
	x*=f;
}
void write(int k){
	if(k>9){
		write(k/10);
	}
	putchar('0'+k%10);
}
bool Mbe;
struct Node{
	int lft,mx,rgt;
	bool is;
	Node(){}
	Node(int k){
		lft=mx=rgt=k;
		is=k;
	}
	friend Node operator+(Node& a,Node& b){
		Node res;
		if(a.is){
			if(b.is){
				res.lft=a.lft+b.lft;
				res.mx=a.mx+b.mx;
				res.rgt=a.rgt+b.rgt;
				res.is=1;
			}else{
				res.lft=a.lft+b.lft;
				res.mx=max(a.lft+b.lft,b.mx);
				res.rgt=b.rgt;
				res.is=0;
			}
		}else{
			if(b.is){
				res.lft=a.lft;
				res.mx=max(a.mx,a.rgt+b.rgt);
				res.rgt=a.rgt+b.rgt;
				res.is=0;
			}else{
				res.lft=a.lft;
				res.mx=max(max(a.mx,b.mx),a.rgt+b.lft);
				res.rgt=b.rgt;
				res.is=0; 
			}
		}
		return res;
	}
} sgt[1100010],pool[110];
int pc=0;
void pushup(int k){
	sgt[k]=sgt[k*2]+sgt[k*2+1];
}
void build(int k,int l,int r){
	if(l==r){
		sgt[k]=Node(0);
	}else{
		int mid=(l+r)>>1;
		build(k*2,l,mid);
		build(k*2+1,mid+1,r);
		pushup(k);
	}
}
void update(int k,int curl,int curr,int pos,int v){
	if(curl==curr){
		sgt[k]=Node(v);
	}else{
		int mid=(curl+curr)>>1;
		if(pos<=mid){
			update(k*2,curl,mid,pos,v);
		}else{
			update(k*2+1,mid+1,curr,pos,v);
		}
		pushup(k);
	}
}
Node& query(int k,int curl,int curr,int ql,int qr){
	//printf("[%lld %lld %lld %lld %lld]\n",k,curl,curr,ql,qr);
	if(ql<=curl && curr<=qr){
		return sgt[k];
	}else{
		int mid=(curl+curr)>>1;
		if(qr<=mid){
			return query(k*2,curl,mid,ql,qr);
		}
		if(mid<ql){
			return query(k*2+1,mid+1,curr,ql,qr);
		}
		int cur=++pc;
		pool[cur]=query(k*2,curl,mid,ql,qr)+query(k*2+1,mid+1,curr,ql,qr);
		return pool[cur];
	}
}
vector<int> e[500010],ps[500010];
int n,q,dpt[500010],beg[500010],ed[500010],val[500010],ptr;
int mn[20][1000010],cnt=0,res[500010],lb[500010],rb[500010],qk[500010];
int ark[20][500010],bec[20][500010],mxd=0;
void dfs(int k,int f){
	dpt[k]=dpt[f]+1;
	mxd=max(mxd,dpt[k]);
	ark[0][k]=dpt[k];
	mn[0][beg[k]=ed[k]=++cnt]=dpt[k];
	for(int i:e[k]){
		if(i!=f){
			dfs(i,k);
			mn[0][ed[k]=++cnt]=dpt[k];
		}
	}
}
int getmn(int l,int r){
	int len=__lg(r-l+1);
	return min(mn[len][l],mn[len][r-(1<<len)+1]);
}
int getbec(int l,int r){
	int len=__lg(r-l+1);
	return min(bec[len][l],bec[len][r-(1<<len)+1]);
}
int getark(int l,int r){
	int len=__lg(r-l+1);
	return max(ark[len][l],ark[len][r-(1<<len)+1]);
}
void solve(int ql,int qr,vector<int>& qs){
	//printf("[%lld %lld]\n",ql,qr);
	if(!qs.size()){
		return;
	}
	if(ql==qr){
		for(int i:qs){
			res[i]=ql;
		}
		return;
	}
	int mid=((ql+qr)>>1)+1;
	while(ptr>mid){
		ptr--;
		for(int i:ps[ptr]){
			update(1,1,n,i,1);
		}
	}
	while(ptr<mid){
		for(int i:ps[ptr]){
			update(1,1,n,i,0);
		}
		ptr++;
	}
	vector<int> ls,rs;
	for(int i:qs){
		pc=0;
		if(query(1,1,n,lb[i],rb[i]).mx<qk[i]){
			ls.push_back(i);
		}else{
			rs.push_back(i);
		}
	}
	solve(ql,mid-1,ls);
	solve(mid,qr,rs);
}
bool Men;
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);
	}
	dfs(1,0);
	for(int i=1;i<=19;i++){
		for(int j=1;j+(1<<i)-1<=cnt;j++){
			mn[i][j]=min(mn[i-1][j],mn[i-1][j+(1<<(i-1))]);
		}
		for(int j=1;j+(1<<i)-1<=n;j++){
			ark[i][j]=max(ark[i-1][j],ark[i-1][j+(1<<(i-1))]);
		}
	}
	for(int i=1;i<n;i++){
		val[i]=getmn(min(beg[i],beg[i+1]),max(ed[i],ed[i+1]));
		ps[val[i]].push_back(i);
		bec[0][i]=val[i];
		//printf("[%lld]",val[i]);
	}
	for(int i=1;i<=19;i++){
		for(int j=1;j+(1<<i)-1<n;j++){
			bec[i][j]=min(bec[i-1][j],bec[i-1][j+(1<<(i-1))]);
		}
	}
	build(1,1,n);
	vector<int> tmp;
	read(q);
	for(int i=1;i<=q;i++){
		read(lb[i]);
		read(rb[i]);
		read(qk[i]);
		if(qk[i]==rb[i]-lb[i]+1){
			res[i]=lb[i]==rb[i]?dpt[lb[i]]:getbec(lb[i],rb[i]-1);
		}
		qk[i]--;
		rb[i]--;
		if(qk[i]){
			tmp.push_back(i);
		}else{
			res[i]=getark(lb[i],rb[i]+1);
		} 
	}
	ptr=n+1;
	solve(1,mxd,tmp);
	for(int i=1;i<=q;i++){
		write(res[i]);
		putchar('\n');
	}
	return 0;
}
