#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 5, M = 2e6 + 5, INF = 1e18, mod = 1e9 + 7;

int n, Q, U[N], V[N], dep[N], dfn[N], st[M][20], Time;
vector <int> g[N];

void dfs(int u, int father)
{
	dep[u] = dep[father] + 1;
	st[dfn[u] = ++Time][0] = father;
	for (auto v : g[u]) if (v != father) dfs(v, u);
}

inline int getmin(int u, int v) { return dfn[u] < dfn[v] ? u : v; }

int LCA(int u, int v)
{
	if (u == v) return u;
	if ((u = dfn[u]) > (v = dfn[v])) swap(u, v);
	int d = __lg(v - u++);
	return getmin(st[u][d], st[v - (1 << d) + 1][d]);
}

signed main()
{
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	cin >> n;
	for (int i = 1, u, v; i < n; i++)
		cin >> u >> v, g[u].push_back(v), g[v].push_back(u), U[i] = u, V[i] = v;
	dfs(1, 0);
	for (int j = 1; j <= __lg(n); j++)
		for (int i = 1; i + (1 << j) - 1 <= n; i++)
			st[i][j] = getmin(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
	cin >> Q;
	while (Q--)
	{
		int l, r, k, ans = 0; cin >> l >> r >> k; // 计算编号为 [l,r] 之间的连续 k 的点的 LCA 深度最大值
		// 线段树维护区间 LCA ? 
		for (int i = l; i + k - 1 <= r; i++)
		{
			int p = i;
			for (int j = i + 1, t = 2; t <= k; t++, j++)
			{
				p = LCA(p, j);
				if (dep[p] <= ans)
					break;
			}
			ans = max(ans, dep[p]);
		}
		cout << ans << endl;
	}
	
	return 0;
}

/*
9:27 20pts.

*/
