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

const int N = 5e5 + 10;

vector <int> g[N];
int n, q;
int dep[N], a[N][30];
int f[N][30];

void dfs (int u, int father) {
	f[u][0] = father;
	dep[u] = dep[father] + 1;
	for (int i = 1; i <= 20; i++)
		f[u][i] = f[f[u][i - 1]][i - 1];
	for (int i = 0; i < g[u].size(); i++) {
		int v = g[u][i];
		if (v == father) continue;
		dfs (v, u);
	}
}

void st () {
	for (int j = 1; j <= 20; j++) 
		for (int i = 1; i + (1 << j) - 1 <= n; i++)
			a[i][j] = min (a[i][j - 1], a[i + (1 << (j - 1))][j - 1]);
}

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];
}

int query (int l, int r) {
	int k = log2 (r - l + 1);
	return min (a[l][k], a[r - (1 << k) + 1][k]);
}

int solve (int l, int r) {
	int last = l;
	for (int i = l + 1; i <= r; i++)
		last = LCA (last, i);
	return last;
}

int main () {
	freopen ("query.in", "r", stdin);
	freopen ("query.out", "w", stdout);
	ios :: sync_with_stdio (false);
	cin.tie (0);
	cout.tie (0); 
	cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		g[u].push_back (v);
		g[v].push_back (u);
	}
	dfs (1, 0);
	cin >> q;
	if (q <= 5000) {
		while (q--) {
			int l, r, k, ans = 1;
			cin >> l >> r >> k;
			for (; l + k - 1 <= r; l++)
				ans = max (ans, dep[solve (l, l + k - 1)]);
			cout << ans << endl;
		}
		return 0;
	}
	for (int i = 1; i <= n; i++) a[i][0] = dep[i];
	st ();
	while (q--) {
		int l, r, k;
		cin >> l >> r >> k;
		if (k == r - l + 1) cout << dep[solve (l, r)] << endl;
		else {
			int ans = 1;
			for (; l + k - 1 <= r; l++)
				ans = max (ans, query (l, l + k - 1));
			cout << ans << endl;
		}
			
	}
	return 0;
} 
