#include<cstdio>

int min(int x,int y){return x<y?x:y;}
int max(int x,int y){return x>y?x:y;}

namespace IO{
	constexpr int SIZE=1<<19;
	char iBuf[SIZE],*iS,*iT,ch;bool f;
	char oBuf[SIZE],*oS=oBuf,*oT=oBuf+SIZE;
	inline char gc(){return(iS==iT&&(iT=(iS=iBuf)+fread(iBuf,1,SIZE,stdin),iS==iT)?EOF:*iS++);}
	template<typename I>inline void read(I &x){
		for(f=0,ch=gc();ch<'0'||ch>'9';ch=gc())if(ch=='-')f=1;
		for(x=0;ch>='0'&&ch<='9';ch=gc())x=(x<<3)+(x<<1)+(ch&15);
		if(f)x=-x;return;
	}
	inline void flush(){fwrite(oBuf,1,oS-oBuf,stdout);oS=oBuf;return;}
	inline void putc(char x){*oS++=x;if(oS==oT)flush();return;}
	template<typename I>inline void write(I x){
		static char qu[55];char*tmp=qu;
		if(x<0)putc('-'),x=-x;
		do*tmp++=(x%10)^48;while(x/=10);
		while(tmp--!=qu)putc(*tmp);
		return;
	}
	struct flusher{~flusher(){flush();}}_;
}
using IO::read;using IO::write;using IO::gc;using IO::putc;

const int N=5e5+5;

int n,Q;
int st[N*2],ne[N*2],la[N],em;
void insert(int x,int y){
	em++;st[em]=y;
	ne[em]=la[x];la[x]=em;
	return;
}

int he[N];
int dep[N],d[N*2],d1;
void dfs(int x,int fa){
	he[x]=d1;
	for(int i=la[x];i!=0;i=ne[i]){
		if(st[i]==fa)continue;
		dep[st[i]]=dep[x]+1;
		d[++d1]=dep[st[i]];
		dfs(st[i],x);
		d[++d1]=dep[x];
	}
	return;
}

int mx[N*4],mn[N*4];
void maketr(int l,int r,int x){
	if(l==r){
		mn[x]=he[l];
		mx[x]=he[l];
		return;
	}
	int mid=(l+r)/2;
	maketr(l,mid,x*2);
	maketr(mid+1,r,x*2+1);
	mn[x]=min(mn[x*2],mn[x*2+1]);
	mx[x]=max(mx[x*2],mx[x*2+1]);
	return;
}
int query_mn(int l,int r,int x,int L,int R){
	if(l>=L&&r<=R)return mn[x];
	if(l>R||r<L)return d1+1;
	int mid=(l+r)/2;
	return min(query_mn(l,mid,x*2,L,R),query_mn(mid+1,r,x*2+1,L,R));
}
int query_mx(int l,int r,int x,int L,int R){
	if(l>=L&&r<=R)return mx[x];
	if(l>R||r<L)return 0;
	int mid=(l+r)/2;
	return max(query_mx(l,mid,x*2,L,R),query_mx(mid+1,r,x*2+1,L,R));
}
int tr[N*8];
void maketree(int l,int r,int x){
	if(l==r){
		tr[x]=d[l];
		return;
	}
	int mid=(l+r)/2;
	maketree(l,mid,x*2);
	maketree(mid+1,r,x*2+1);
	tr[x]=min(tr[x*2],tr[x*2+1]);
	return;
}
int query(int l,int r,int x,int L,int R){
	if(l>=L&&r<=R)return tr[x];
	if(l>R||r<L)return n+1;
	int mid=(l+r)/2;
	return min(query(l,mid,x*2,L,R),query(mid+1,r,x*2+1,L,R));
}

int Ans;

int main(){
	
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	
	read(n);
	for(int i=1;i<n;i++){
		int x,y;read(x);read(y);
		insert(x,y);insert(y,x);
	}
	dep[1]=1;
	he[1]=1;d[++d1]=1;
	dfs(1,0);
	
	maketr(1,n,1);
	maketree(1,d1,1);
	
	read(Q);
	while(Q--){
		
		Ans=0;
		
		int l,r,k;read(l);read(r);read(k);
		for(int i=l;i<=r-k+1;i++){
			int le=query_mn(1,n,1,i,i+k-1);
			int ri=query_mx(1,n,1,i,i+k-1);
			Ans=max(Ans,query(1,d1,1,le,ri));
		}
		
		write(Ans);putc('\n');
		
	}
	
	return 0;
}
