#include<bits/stdc++.h>
#define ll long long
#define D double
#define F(i,j,n) for(register int i=j;i<=n;i++)
#define lc id*2
#define rc id*2+1
using namespace std;
const int N=1e6+10;
ll n,m,k,x,y,u,v,w,cnt,ans,sum,t,T,l,r;
ll mn=1e9,mx=-1e9,p;
ll c;
ll head[N];
struct Tree{
	ll nxt,to;
}tr[N];
void add(ll u,ll v){
	t++;
	tr[t].to=v;
	tr[t].nxt=head[u];
	head[u]=t;
}
ll st[N][25];
queue<ll> q;
void bfs(){
	st[1][0]=1;
	q.push(1);
	while(!q.empty()){
		ll u=q.front();
		q.pop();
		for(ll i=head[u];i;i=tr[i].nxt){
			ll v=tr[i].to;
			if(!st[v][0]) st[v][0]=st[u][0]+1,q.push(v);
		}
	}
}
ll query(ll l,ll r){
	ll len=log2(r-l+1);
	return min(st[l][len],st[r-(1<<len)+1][len]);
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin>>n;
	F(i,1,n-1) cin>>u>>v,add(u,v),add(v,u);
	bfs();
	F(len,1,20) for(ll i=1;i+(1ll<<len)-1<=n;i++) st[i][len]=min(st[i][len-1],st[i+(1ll<<(len-1))][len-1]);
	cin>>m;
	F(i,1,m){
		ans=0;
		cin>>l>>r>>k;
		for(ll x=l;x+k-1<=r;x++) ans=max(ans,query(x,x+k-1));
		cout<<ans<<"\n";
	}

	return 0;
}

