#include<bits/stdc++.h>
#define ll long long 
#define LL __int128
#define fi first
#define se second
using namespace std;

const int maxn = 5e5 + 5;
int n, head[maxn], cnt, dep[maxn], fa[maxn][30], q;
struct edge{int v, nxt;}E[maxn << 1];

void add(int u, int v){
	E[++cnt] = {v, head[u]};
	head[u] = cnt;
}

void dfs(int u, int fath){
	dep[u] = dep[fa[u][0] = fath] + 1; for(int i = 1; i <= 25; i++) fa[u][i] = fa[fa[u][i - 1]][i - 1];
	for(int i = head[u]; i; i = E[i].nxt){
		int v = E[i].v;
		if(v == fath) continue;
		dfs(v, u);
	}
}

int lca(int u, int v){
	if(dep[u] < dep[v]) swap(u, v);
	for(int i = 25; i >= 0; i--) if(dep[fa[u][i]] >= dep[v]) u = fa[u][i];
	if(u == v) return u;
	for(int i = 25; i >= 0; i--) if(fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
	return fa[u][0];
}

int solve(int l, int r){
	int s = l;
	for(int i = l + 1; i <= r; i++) s = lca(s, i);
	return dep[s];
}

signed main(){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);

	cin >> n;
	for(int i = 1, u, v; i < n; i++) cin >> u >> v, add(u, v), add(v, u);
	cin >> q;
	dfs(1, 0);
	while(q--){
		int l, r, k; cin >> l >> r >> k;
		int ans = 0;
		for(int i = l; i + k - 1 <= r; i++){
			ans = max(ans, solve(i, i + k - 1));
		}
		cout << ans << '\n';
	}

	return 0;
}