#include <bits/stdc++.h>
using namespace std;
int n , q , a[20][500010] , d[500010] , l , r , k , f[500010];
int sum , ans;
vector <int> v[500010] , v_1[500010];
void build (int x , int deep) { 
	d[x] = deep;
	for (int i = 0;i < v_1[x].size ();i ++) {
		if ( d[v_1[x][i]] ) continue;
		v[x].push_back ( v_1[x][i] );
		f[v_1[x][i]] = x;
		build (v_1[x][i] , deep + 1); 
	}
	return;
}
int ff (int x , int y) {
	while (d[x] < d[y]) y = f[y];
	while (d[x] > d[y]) x = f[x]; 
	while (x != y) x = f[x] , y = f[y];
	return d[x];
}
int main () {
	freopen ("query.in" , "r" , stdin);
	freopen ("query.out" , "w" , stdout);
	cin >> n;
	for (int i = 1;i < n;i ++) {
		cin >> l >> r;
		v_1[l].push_back (r);
		v_1[r].push_back (l);
	}
	build (1 , 1);
	cin >> q;
	while (q --) {
		cin >> l >> r >> k;
		ans = 0;
		if (k == 1) {
			for (int i = l;i <= r;i ++) {
				ans = max (ans , d[i]);
			} 
			cout << ans << '\n';
			continue;
		}
		for (int i = l;i <= r - k + 1;i ++) {
			sum = INT_MAX;
			for (int j = i;j <= i + k - 2;j ++) {
				sum = min (sum , ff (j , j + 1));
			}
			ans = max (ans , sum);
		}
		cout << ans << '\n';
	} 
	
	return 0;
}




 
