#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define rep(i,x,y) for(ll i=x;i<=y;i++)

const ll N=5e5+10;
ll n,fa[N],dep[N],siz[N],hs[N],top[N],Q,mem[N][25],pow2[25];
vector<ll> g[N];

void dfs1(ll p,ll lst){
//	cout<<"dfs1:"<<p<<'\n';
	fa[p]=lst;
	dep[p]=dep[lst]+1;
	siz[p]=1;
	
	for(ll i:g[p]){
		if(i==lst) continue;
		
		dfs1(i,p);
		siz[p]+=siz[i];
		
		if(siz[i]>siz[hs[p]]) hs[p]=i;
	}
}

void dfs2(ll p,ll curt){
	top[p]=curt;
	
	if(hs[p]==0) return;
	
	for(ll i:g[p]){
		if(i==fa[p]) continue;
		
		if(i==hs[p]) dfs2(i,curt);
		else dfs2(i,i);
	}
}

ll lca(ll x,ll y){
	if(x==y) return x;
	
	while(top[x]!=top[y]){
		if(dep[top[x]]<dep[top[y]]) swap(x,y);
		
		x=fa[top[x]];
	}
	
	if(dep[x]<dep[y]) return x;
	else return y;
}

ll cal(ll l,ll r){
	if(l==r) return l;
	
	ll i=24,ret=l;
	
	while(l<=r){
		while(l+pow2[i]-1>r) i--;
		
		ret=lca(ret,mem[l][i]);
		l+=pow2[i];
	}
	
	return ret;
}

int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	pow2[0]=1;
//	system("pause");
	
	rep(i,1,24) pow2[i]=pow2[i-1]*2;
	
//	rep(i,0,24) cout<<pow2[i]<<' ';
//	
//	cout<<'\n';
	cin>>n;
	
	rep(i,1,n-1){
		ll u,v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	
	dfs1(1,0);
//	cout<<"dfs1 done\n";
	dfs2(1,1);
//	cout<<"dfs2 done\n";
	
//	rep(i,1,n) cout<<top[i]<<' ';
	
//	rep(i,1,n){
//		rep(j,i+1,n) cout<<i<<' '<<j<<' '<<lca(i,j)<<'\n';
//	}
	
//	system("pause");
	
	for(ll i=n;i>0;i--){
		mem[i][0]=i;
		
		for(ll j=1;;j++){
			if(i+pow2[j]-1>n) break;
			
			mem[i][j]=lca(mem[i][j-1],mem[i+pow2[j-1]][j-1]);
//			cout<<i<<' '<<i+pow2[j]-1<<' '<<mem[i][j]<<'\n';
		}
	}
	
//	system("pause");
	cin>>Q;
	
	while(Q--){
		ll l,r,k;
		cin>>l>>r>>k;
		ll ans=0;
		
		rep(i,l,r-k+1){
			ll j=i+k-1;
//			cout<<"i="<<i<<",j="<<j<<'\n';
			ans=max(ans,dep[cal(i,j)]);
		}
		
		cout<<ans<<'\n';
	}
	
	return 0;
}
