#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = l; i <= r; i ++)
#define per(i, r, l) for (int i = r; i >= l; i --)
/*
总而言之，从尝试做出计数题开始就失败了/ll
这个题如果给我时间应该写的完。
考虑 dsu on tree + 支配点对，然后考虑树上往左边 / 右边连续的颜色段。
然后对于 [l, r] 询问等价于对于 [l, r - k + 1] 询问那一堆 l + len >= r 的颜色段的并的最大值。
这个是容易维护的，可以使用 multiset + 扫描线解决，时间复杂度 O(n log^2 n)。 
*/
using namespace std;

const int _ = 5e5 + 5;
int n, q, dfc;
int dep[_], pa[_][20], st[_][20][2], dfn[_], lgr[_], tr[_];
vector <int> e[_];

namespace subtask {
	const int __ = 5005;
	int lc[__][__];
	void work() {
		auto getlca = [](int x, int y) -> int {
			if (dep[x] < dep[y]) 
				swap(x, y);
			int d = dep[x] - dep[y];
			rep(i, 0, 19) if (d & (1 << i)) x = pa[x][i];
			if (x == y) return x;
			per(i, 19, 0) if (pa[x][i] ^ pa[y][i]) x = pa[x][i], y = pa[y][i];
			return pa[x][0];
		} ;
		rep(i, 1, n) {
			lc[i][i] = i;
			rep(j, i + 1, n) {
				lc[i][j] = getlca(lc[i][j - 1], j);	
			}
		} 
		cin >> q;
		rep(i, 1, q) {
			int x, y, k, ans = 0;
			scanf("%d%d%d", &x, &y, &k);
			rep(j, x, y - k + 1)
				ans = max(ans, dep[lc[j][j + k - 1]]);
			printf("%d\n", ans);
		} 
	}
}
int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	cin >> n;
	rep(i, 1, n - 1) {
		int x, y;
		scanf("%d%d", &x, &y);
		e[x].push_back(y), e[y].push_back(x);
	}
	auto dfs1 = [&](auto &self, int x, int fa) -> void {
		dep[x] = dep[fa] + 1;
		dfn[x] = ++ dfc;
		tr[dfc] = x;
		pa[x][0] = fa;
		rep(i, 1, 19) pa[x][i] = pa[pa[x][i - 1]][i - 1];
		for (int y : e[x]) {
			if (y == fa) continue ;
			self(self, y, x);
		} 
	} ;
	dfs1(dfs1, 1, 0);
	if (n <= 5000)
		subtask :: work();
	else {
		auto getlca = [](int x, int y) -> int {
			if (dep[x] < dep[y]) 
				swap(x, y);
			int d = dep[x] - dep[y];
			rep(i, 0, 19) if (d & (1 << i)) x = pa[x][i];
			if (x == y) return x;
			per(i, 19, 0) if (pa[x][i] ^ pa[y][i]) x = pa[x][i], y = pa[y][i];
			return pa[x][0];
		} ;
//		int st[_][20][2];
		lgr[0] = -1;
		rep(i, 1, n) st[i][0][0] = st[i][0][1] = dfn[i], lgr[i] = lgr[i >> 1] + 1;
		rep(i, 1, 19) rep(j, 1, n - (1 << i) + 1)
			st[j][i][0] = min(st[j][i - 1][0], st[j + (1 << i - 1)][i - 1][0]),
			st[j][i][1] = max(st[j][i - 1][1], st[j + (1 << i - 1)][i - 1][1]);
		auto qry_lca = [&](int l, int r) -> int {
			int k = lgr[r - l + 1];
			int mn = min(st[l][k][0], st[r - (1 << k) + 1][k][0]),
				mx = max(st[l][k][1], st[r - (1 << k) + 1][k][1]);
//			cout << mn << ' ' << mx << '\n';
			mn = tr[mn], mx = tr[mx];
			
			return dep[getlca(mn, mx)];
		} ;
		cin >> q;
		rep(i, 1, q) {
			int l, r, k;
			scanf("%d%d%d", &l, &r, &k);
			printf("%d\n", qry_lca(l, r));
		} 
	}
	return 0;
}
/*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 4
2 4 3
3 3 1

*/

