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

const int maxn = 5e5 + 5;

int n, ui, vi, q, li, ri, ki, ans_dpth, cur_lca;
int lg[maxn];
int cnt[maxn];
int dpth[maxn], ancestor[maxn][20];
bool spe_A = true;
vector<int>edge[maxn];

void dfs(int x, int fa){
	for(auto i : edge[x]){
		if(i == fa){
			continue;
		}
		dpth[i] = dpth[x] + 1;
		dfs(i, x);
	}
	return;
}

void solve_spe(){
	cin >> q;
	dfs(1, 0);
	for(int i = 1; i <= q; i++){
		scanf("%d %d %d", &li, &ri, &ki);
		int k = ki;
		ans_dpth = 0;
		for(int i = li; i + k - 1 <= ri; i++){
			cur_lca = i;
			for(int j = 1; j < k; j++){
				if(dpth[i + j] < dpth[cur_lca]){
					cur_lca = i + j;
				}
			}
			ans_dpth = max(ans_dpth, dpth[cur_lca]);
		}
		printf("%d\n", ans_dpth);
	}
	return;
}

void cnt_ancestor(int x, int fa){
	for(auto i : edge[x]){
		if(i == fa){
			continue;
		}
		dpth[i] = dpth[x] + 1;
		cnt_ancestor(i, x);
	}
	ancestor[x][0] = fa;
	for(int i = 1; i < lg[dpth[i]]; i++){
		ancestor[x][i] = ancestor[ancestor[x][i - 1]][i - 1];
	}
	return;
}

int gt_lca(int xi, int yi){
	if(dpth[xi] < dpth[yi]){
		swap(xi, yi);
	}
	while(dpth[xi] > dpth[yi]){
		xi = ancestor[xi][lg[yi - xi]];
	}
	if(xi == yi){
		return xi;
	}
	for(int i = lg[xi]; i >= 0; i--){
		if(ancestor[xi][i] != ancestor[yi][i]){
			xi = ancestor[xi][i];
			yi = ancestor[yi][i];
		}
	}
	return ancestor[xi][0];
} 

int main(){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	scanf("%d", &n);
	for(int i = 1; i < n; i++){
		scanf("%d %d", &ui, &vi);
		edge[ui].push_back(vi);
		edge[vi].push_back(ui);
		lg[i + 1] = lg[(i + 1) >> 1] + 1; 
		cnt[ui]++;
		cnt[vi]++;
		if(cnt[ui] > 2 || cnt[vi] > 2){
			spe_A = false;
		}
	}
	if(spe_A){
		solve_spe();
		return 0;
	}
	dpth[1] = 1;
	cnt_ancestor(1, 0);
	cin >> q;
	for(int i = 1; i <= q; i++){
		scanf("%d %d %d", &li, &ri, &ki);
		ans_dpth = 0;
		for(int k = ki; k <= (ri - li + 1); k++){
			for(int i = li; i + k - 1 <= ri; i++){
				cur_lca = i;
				for(int j = 1; j < k; j++){
					cur_lca = gt_lca(cur_lca, i + j);
				}
				ans_dpth = max(ans_dpth, dpth[cur_lca]);
			}
		}
		printf("%d\n", ans_dpth);
	}
	return 0;
} 
