#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 5e5 + 50;
int n, q, l, r, k, dep[maxn], in[maxn], f[maxn][30], head[maxn], cnt, lc[5005][5005];

struct node {
	int to, nxt;
} e[maxn << 1];

void add(int from, int to) {
	e[++cnt] = {to, head[from]};
	head[from] = cnt;
}

void dfs(int u, int fa){
	dep[u] = dep[fa] + 1, f[u][0] = fa;
	for(int i = 1; i <= 20; i++){
		f[u][i] = f[f[u][i - 1]][i - 1];
	}
	for(int i = head[u]; i; i = e[i].nxt){
		int to = e[i].to;
		if(to == fa) continue;
		dfs(to, u);
	}
}

int lca(int x, int y){
	if(dep[x] < dep[y]) swap(x, y);
	for(int i = 20; i >= 0; i--){
		if(dep[f[x][i]] >= dep[y]) x = f[x][i];
	}
	if(x == y) return x;
	for(int i = 20; i >= 0; i--){
		if(f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
	}
	return f[x][0];
}

signed 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, a, b; i < n; i++) {
		cin >> a >> b;
		add(a, b), add(b, a);
	}
	dfs(1, 0);
	cin >> q;
	for(int i = 1; i <= q; i++) {
		cin >> l >> r >> k;
		int ans = 0;
		for(int j = l; j <= r - k + 1; j++) {
			int lcx = j;
			for(int o = j + 1; o <= j + k - 1; o++) lcx = lca(lcx, o);
//			cout << lcx << ' ';
			ans = max(ans, dep[lcx]);
		}
		cout << ans << '\n';
	}
	return 0;
}
/*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3
*/
