#include<bits/stdc++.h>
using namespace std;
int n,Q,root=1;
vector<int>edge[500005];
int f[23][500005],dep[500005];
void dfs(int u,int v,int deps){
	f[0][v]=u;
	for(int i=1;i<=20;++i){
		f[i][v]=f[i-1][f[i-1][v]];
	}
	dep[v]=deps;
	for(auto i:edge[v]){
		if(i!=u){
			dfs(v,i,deps+1);
		}
	}
	
}
int lca(int x,int y){
	if(dep[x]>dep[y])swap(x,y);
	for(int i=20;i>=0;--i){
		if(dep[f[i][y]]>=dep[x])y=f[i][y];
	}
	if(x==y)return x;
	for(int i=20;i>=0;--i){
		if(f[i][x]!=f[i][y]){
			x=f[i][x];
			y=f[i][y];
		}
	}
	return f[0][x];
}
/*
int q[2500005],head,tail;
inline void qpush(int& x){
	q[++tail]=x;
	return;
}
inline int qback(){
	return q[tail];
}
inline int qbackpop(){
	return q[tail--];
}
inline int qfront(){
	return q[head+1];
}
inline int qfrontpop(){
	return q[++head];
}
inline bool qempty(){
	return head==tail;
}
*/
struct ST{
	int t[(1<<21)];
	int updata(int x){
		t[x]=lca(t[x*2],t[x*2+1]);
	}
	void build(int x,int l,int r){
		
		if(l==r){
			t[x]=l;
			return;
		}
		
		int mid=(l+r)/2;
		build(x*2,l,mid);
		build(x*2+1,mid+1,r);
		updata(x);
	}
	int find(int x,int l,int r,int fl,int fr){
		//cout<<x<<":("<<t[x]<<") "<<l<<' '<<r<<"|"<<fl<<" "<<fr<<"\n";
		if(fl<=l&&r<=fr)return t[x];
		int mid=(l+r)/2;
		if(fr<=mid)return find(x*2,l,mid,fl,fr);
		if(mid<fl)return find(x*2+1,mid+1,r,fl,fr);
		return lca(find(x*2,l,mid,fl,fr),find(x*2+1,mid+1,r,fl,fr));
	}
}T;
int gx[500005];
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<n;++i){
		int a,b;
		scanf("%d%d",&a,&b);
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	dfs(0,1,1);
	T.build(1,1,n);
	//OK
	scanf("%d",&Q);
	while(Q--){
		//head=tail=1;
		int L,R,k,ans=0,cnt;
		scanf("%d%d%d",&L,&R,&k);
		for(cnt=L;cnt<=R;++cnt){
			//cout<<"RE:"<<T.find(1,1,n,cnt,cnt+k-1)<<"\n";
			ans=max(ans,dep[T.find(1,1,n,cnt,cnt+k-1)]);
		}
		printf("%d\n",ans);
	}
	
}
/*
5
1 2
2 3
2 4
4 5
7
1 5 1
1 5 2
1 5 3
1 5 4
3 5 2
2 5 3
2 5 4
int mian()
//freopen("query.out","r",stdin);
I am a Grade 9 student.
After this NOIP,I will AFO.
I know I can not get a good grade in the NOIP.
Maybe 100 points,or less than it.
I can not stop me from AFO.
If there are someone looking it,I can be little warm.
Luogu ID:mywzj_mo
*/
