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

#define N 200010
int dep[N], f[N][30], ans, n, q, Madep;
vector < int > tr[N];

void dfs1(int x, int fa) {
	dep[x] = dep[fa] + 1;
	Madep = max(Madep, dep[x]);
	f[x][0] = fa;
	for (int i = 1; i <= 21; ++i) 
		f[x][i] = f[f[x][i - 1]][i - 1];
	for (int y : tr[x]) 
		if (y != fa) dfs1(y, x);
}
int lca(int x, int y) {
	if (dep[x] < dep[y]) swap(x, y);
	for (int i = 21; ~i; --i)
		if (dep[f[x][i]] >= dep[y]) x = f[x][i];
	if (x == y) return x;
//	puts("qwq");
	for (int i = 21; ~i; --i)
		if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
	return f[x][0];
}

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	
	scanf("%d", &n);
	for (int i = 1; i < n; ++i) {
		int u, v;
		scanf("%d %d", &u, &v);
		tr[u].push_back(v);
		tr[v].push_back(u);
	}
	dfs1(1, 0);
/*	if (Madep == n) {
		scanf("%d", &q);
		while (q--) {
			int l, r, k;
			scanf("%d %d %d", &l, &r, &k);
			
		}
	}
*/	
	scanf("%d", &q);
	while (q--) {
		int l, r, k;
		scanf("%d %d %d", &l, &r, &k);
		ans = 0;
		for (int i = l; i + k - 1 <= r; ++i) {
			int _lca = i;
	//		cout << i << endl;
			for (int j = i + 1; j <= i + k - 1; ++j) {
				_lca = lca(_lca, j);
	//			cout << _lca << "??\n";
			}
			ans = max(ans, dep[_lca]);
	//		cout << ans << "---\n";
		}
		printf("%d\n", ans);
	}
	return 0;
} 
/*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3
*/
