#include<bits/stdc++.h>
#define ll long long
#define lc c<<1
#define rc c<<1|1
using namespace std;
ll n,p;
vector<ll> e[500005];
ll dep[500005];
bool vis[500005];
ll st[500005][20];
ll lo[500005];
void init(){
	lo[1] = 0;
	ll now = 2;
	for(int i=2;i<=n;i++){
		lo[i] = lo[i] + (i == now);
		if(i == now) now *= 2;
	}
	for(int i=1;i<=n;i++){
		st[i][0] = dep[i];
		for(int j=1;i + (2<<j) <= n;j++){
			st[i][j] = max(st[i][j-1],st[i +  (j<<1)][j-1]);
		}
	}
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin>>n;
	ll u,v;
	for(int i=1;i<n;i++){
		cin>>u>>v;
		e[u].push_back(v);
		e[v].push_back(u);
	}
	ll l,r,k;
	vis[1] = 1;dep[1] = 1;
	queue<ll> q;
	q.push(1);
	while(!q.empty()){
		u = q.front(); q.pop();
		for(auto v : e[u]){
			if(vis[v]) continue;
			vis[v] = 1;
			dep[v] = dep[u] + 1;
			q.push(v);
		}
	}
	init();
	cin>>p;
	for(int i=1;i<=p;i++){
		cin>>l>>r>>k;
		cout<<max(st[l][(lo[r - l + 1])],st[r - (2 << (lo[r - l + 1])) + 1][(lo[r - l + 1])])<<endl;
	}
	return 0;
}
