#include <bits/stdc++.h>
using namespace std;
vector <int> v[5001];
int lca[5001][5001];
int st[5001][20];
int dep[5001];
void dfs(int x, int fa) {
	dep[x] = dep[fa] + 1;
	st[x][0] = fa;
	for (int i = 1; i < 20; i++)
		st[x][i] = st[st[x][i - 1]][i - 1];
	for (int i = 0; i < v[x].size(); i++)
		if (v[x][i] != fa) dfs(v[x][i], x);
}
int LCA(int x, int y) {
	if (dep[x] < dep[y]) swap(x, y);
	for (int i = 12; ~i; i--)
		if (dep[st[x][i]] >= dep[y])
			x = st[x][i];
	if (x == y) return x;
	for (int i = 12; ~i; i--)
		if (st[x][i] != st[y][i])
			x = st[x][i], y = st[y][i];
	return st[x][0];
}
int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	int n, q, x, y, k;
	scanf("%d", &n);
	for (int i = 1; i < n; i++)
		scanf("%d%d", &x, &y),
		v[x].push_back(y),
		v[y].push_back(x);
	dfs(1, 0);
	for (int i = 1; i <= n; i++) {
		lca[i][i] = i;
		for (int j = i + 1; j <= n; j++)
			lca[i][j] = LCA(lca[i][j - 1], j);
	}
	scanf("%d", &q);
	while (q--) {
		int ans = 0;
		scanf("%d%d%d", &x, &y, &k);
		for (int i = x; i <= y - k + 1; i++)
			ans = max(ans, dep[lca[i][i + k - 1]]);
		printf("%d\n", ans);
	}
	return 0;
}
