# include <bits/stdc++.h>
# define N (int)5e5+10
using namespace std ;
int n , dep [N],s[N][20],q;
vector<int>g[N] ;
void dfs ( int x , int fa )
{
	for ( int i : g [ x ])
	{
		if ( i == fa )
			continue ;
		s[i][0]=dep[x]+1;
		dep [ i ] = dep [ x ] + 1 ;
		dfs ( i , x ) ;
	}
	return ;
}
int main ()
{
	freopen ( "query.in" , "r" , stdin ) ;
	freopen ( "query.out" , "w" , stdout ) ; 
	ios :: sync_with_stdio ( 0 ) ;
	cin . tie ( 0 ) ;
	cout . tie ( 0 ) ;
	cin >> n ;
	for ( int i = 1 ; i < n ; i ++ )
	{
		int u , v ;
		cin >> u >> v ;
		g [ u ] . push_back ( v ) ;
		g [ v ] . push_back ( u ) ;
	}
	dfs ( 1 , -1 ) ;
	for ( int j = 1 ; j <= 20 ; j ++ )
	for ( int i =  1 ;i <=n-(1<<j); i ++ )
	{
		s [ i ] [ j ] = min ( s [ i ] [ j - 1 ] , s [ i + ( 1 << ( j - 1 ) ) ] [ j - 1 ] ) ;
	}
	cin >> q ;
	while ( q -- )
	{
		int l , r , k ;
		cin >> l >> r >> k ;
		int lg = log2 ( r - l + 1 ) ;
		cout << max ( s [ l ] [ lg ] , s [ r - ( 1 << lg ) + 1 ] [ lg ] ) << '\n' ;
	}
	return 0 ;
}
