#include <bits/stdc++.h>
#define int long long
#define debug(x) cerr << #x << ": " << x << endl
using namespace std;

const int MAXN = 5e5 + 7;
int depth[MAXN], fa[MAXN], euler[MAXN << 1], st[MAXN << 1][20], stlca[MAXN][20], fst[MAXN], lg22[MAXN << 1], dfn[MAXN], ant[MAXN], vis[MAXN];
int euler_cnt, ans, dfn_cnt, n, q, mxdp;

vector<int> to[MAXN];
void dfs(int idx, int fat = 0)
{
	euler[++euler_cnt] = idx;
	fst[idx] = euler_cnt;
	dfn[idx] = ++dfn_cnt;
	ant[dfn_cnt] = idx;
	depth[idx] = depth[fat] + 1;
	mxdp = max(mxdp, depth[idx]);
	fa[idx] = fat;
	for (int i : to[idx])
		if (i != fat)
			dfs(i, idx);
}

int lca(int l, int r)
{
	l = fst[l], r = fst[r];
	if (l > r) swap(l, r);
	int d = lg22[r - l + 1];
	return ant[min(st[l][d], st[r - (1ll << d) + 1][d])];
}

void init()
{
	for (int i = 1; i <= euler_cnt; i++) st[i][0] = dfn[euler[i]];
	for (int j = 1, p = 1; j < 20; j++, p <<= 1)
		for (int i = 1; i + 2 * p <= euler_cnt + 1; i++)
			st[i][j] = min(st[i][j - 1], st[i + p][j - 1]);
	for (int i = 1; i <= n; i++) stlca[i][0] = i;
	for (int j = 1, p = 1; j < 20; j++, p <<= 1)
		for (int i = 1; i + 2 * p <= n + 1; i++)
			stlca[i][j] = lca(stlca[i][j - 1], stlca[i + p][j - 1]);
}

int query(int l, int r)
{
	int d = lg22[r - l + 1];
	return lca(stlca[l][d], stlca[r - (1ll << d) + 1][d]);
}

signed main()
{
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	lg22[1] = 0;
	for (int i = 2; i < (MAXN << 1); i++) lg22[i] = lg22[i / 2] + 1;
	cin >> n;
	for (int i = 1; i < n; i++)
	{
		int u, v; cin >> u >> v;
		to[u].push_back(v);
		to[v].push_back(u);
	}
	dfs(1);
	init();
	cin >> q;
	while (q--)
	{
		int ans = 0;
		int l, r, k; cin >> l >> r >> k;
		for (int i = l; i <= r - k + 1; i++)
		{
			int lp = i, rp = i + k - 1;
			ans = max(ans, depth[query(lp, rp)]);
		}
		cout << ans << endl;
	}
}

