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

const int N = 500010;

int t, n, q, cnt;
int head[N], to[N << 1], nxt[N << 1], lg[N];
int f[N][30], g[N][30], dep[N], deg[N];

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

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

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

void ST_create()
{
	for (int i = 1; i <= n; i++) g[i][0] = i;
	for (int j = 1; j <= 20; j++)
		for (int i = 1; i <= n - (1 << j) + 1; i++)
			g[i][j] = lca(g[i][j - 1], g[i + (1 << j - 1)][j - 1]);
}

int query(int l, int r)
{
	int k = lg[r - l + 1];
	return lca(g[l][k], g[r - (1 << k) + 1][k]);
}

signed main()
{
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	
	lg[1] = lg[0] = 0;
	for (int i = 2; i < N; i++) lg[i] = lg[i >> 1] + 1;
	
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) head[i] = deg[i] = 0;
	cnt = 0;
	for (int i = 1; i < n; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		add(u, v), add(v, u);
		deg[u]++;
		deg[v]++;
	}
	dep[1] = 1;
	dfs(1);
	ST_create();
	scanf("%d", &q);
	while (q--)
	{
		int l, r, k;
		scanf("%d%d%d", &l, &r, &k);
		int ans = 0;
		for (int i = l; i <= r - k + 1; i++)
			ans = max(ans, dep[query(i, i + k - 1)]);
		printf("%d\n", ans);
	}
	return 0;
}
