#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int dep[MAXN];
int tong[MAXN];
int main(){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	int n;
	cin >> n;
	for(int i = 1; i < n; i++){
		int u, v;
		cin >> u >> v;
		dep[v] = i + 1;
	}
	dep[1] = 1;
	int q;
	cin >> q;
	for(int i = 1; i <= q; i++){
		int l, r, k;
		cin >> l >> r >> k;
		memset(tong, 0, sizeof(tong));
		int ans = 0;
		int MIN = MAXN;
		for(int i = l; i < l + k; i++){
			tong[dep[i]]++;
			MIN = min(MIN, dep[i]); 
		}
		ans = max(ans, MIN);
		for(int i = l + k; i <= r; i++){
			tong[dep[i - k]]--;
			tong[dep[i]]++;
			if(dep[i] < MIN){
				MIN = dep[i];
			}
			else if(dep[i - k] == MIN){
				for(int i = dep[i - k + 1]; i <= MAXN; i++){
					if(tong[i] > 0){
						MIN = i;
						break;
					}
				}
			}
			ans = max(ans, MIN);
		}
		cout << ans << "\n";
	}
	return 0;
}

