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

const int MAXn = 500005;
const int MAXE = MAXn << 1;
const int MAXt = MAXn << 2;
int tot, to[MAXE], nxt[MAXE], head[MAXn];
int dep[MAXn];
int el[MAXn << 1][21], et;
int dp[MAXn << 1][21];
//That's important.
int iv[MAXn];
int qlg[MAXn << 1];
void edgadd(int u, int v) {
	to[++tot] = v;
	nxt[tot] = head[u];
	head[u] = tot;
}
void dfs(int u, int fa) {
	el[++et][0] = u;
	dp[et][0] = dep[u];
	iv[u] = et;
	for (int i = head[u]; i; i = nxt[i]) {
		int v = to[i];
		if(v == fa) {
			continue;
		}
		dep[v] = dep[u] + 1;
		dfs(v, u);
		el[++et][0] = u;
		dp[et][0] = dep[u];
	}
}
int st[MAXn][21];
int ddeg[MAXn];
struct QueryNode {
	int l, r, k;
} qry[500005];
int QLCA(int l, int r) {
	int x = iv[l], y = iv[r];
	if(x > y) {
		swap(x, y);
	}
	int dis = y - x + 1;
	int ldis = qlg[dis];
	int rdis = 1 << ldis;
	int ypos = y - rdis + 1;
	int A = dp[x][ldis], B = dp[ypos][ldis];
	return (A < B) ? (el[x][ldis]) : (el[ypos][ldis]);
}


int main(void) {
#ifndef DEB_MAC
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
#endif
	int n;
	cin >> n;
	for (int i = 1; i < n; ++i) {
		int u, v;
		cin >> u >> v;
		edgadd(u, v);
		edgadd(v, u);
		++ddeg[u];
		++ddeg[v];
	}
//	if(tc613 == n) {
//		dfs_on_chain(1, 0);
//	}
	dep[1] = 1;
	//Specially
	dfs(1, 0);
	qlg[0] = -1;
	for (int i = 1; i <= et; ++i) {
		qlg[i] = qlg[i >> 1] + 1;
	}
	for (int i = 1, j = 1, k = 2; k <= et; ++i, j <<= 1, k <<= 1) {
		for (int z = 1; (z + k - 1) <= et; ++z) {
			int A = dp[z][i - 1], B = dp[z + j][i - 1];
			if(A < B) {
				el[z][i] = el[z][i - 1];
				dp[z][i] = A;
			} else {
				el[z][i] = el[z + j][i - 1];
				dp[z][i] = B;
			}
		}
	}
	int q;
	cin >> q;
//	do {
//		//test LCA. remember to remove.
//		while(q--) {
//			int l, r;
//			cin >> l >> r;
//			cout << QLCA(l, r) << '\n';
//		}
//	}while(0);

	int testcase14 = 0;
	for (int i = 1; i <= q; ++i) {
		cin >> qry[i].l >> qry[i].r >> qry[i].k;
		if(qry[i].k == qry[i].r - qry[i].l + 1) {
			++testcase14;
		}
	}
	for (int i = 1; i <= n; ++i) {
		st[i][0] = i;
	}
	for (int i = 1, j = 1, k = 2; k <= n; ++i, j <<= 1, k <<= 1) {
		for (int z = 1; (z + k - 2) <= n; ++z) {
			st[z][i] = QLCA(st[z][i - 1], st[z + j][i - 1]);
		}
	}
	auto QLCA_STAR = [&](int x, int y) {
		int dis = y - x + 1;
		int ldis = qlg[dis];
		int rdis = 1 << ldis;
		return QLCA(st[x][ldis], st[y - rdis + 1][ldis]);
	};

	if(testcase14 == q) {
		//lim B
		//ST * 2
		for (int i = 1; i <= q; ++i) {
			//Validated.
			cout << dep[QLCA_STAR(qry[i].l, qry[i].r)] << '\n';
		}
		return 0;
	}
	
	
	for (int i = 1; i <= q; ++i) {
		int spot = qry[i].l + qry[i].k - 1;
		int ans = dep[QLCA_STAR(qry[i].l, spot)];
		//warn of meaning of i, j, k.
		for (int j = qry[i].l + 1, k = spot + 1; k <= qry[i].r; ++j, ++k) {
			ans = max(ans, dep[QLCA_STAR(j, k)]);
		}
		cout << ans << '\n';
	}
	return 0;
}
