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

#define ofor(i, a, b) for (int i = a; i < b; i++)
#define cfor(i, a, b) for (int i = a; i <= b; i++)
#define bfor(i, a, b) for (int i = a; i >= b; i--)
#define mset(a, x) memset(a, x, sizeof(a))
const int X = 5e5 + 5;

int n, Q, ans;
vector<int> to[X];
bool chain;

int dep[X], fa[X][20];

queue<int> bfs_q;
void build() {
	bfs_q.push(1);
	dep[1] = 1;
	while (not bfs_q.empty()) {
		int u = bfs_q.front(); bfs_q.pop();
		for (int v: to[u]) {
			if (v == fa[u][0]) continue;
			dep[v] = dep[u] + 1;
			fa[v][0] = u;
			cfor (i, 1, 19)
				fa[v][i] = fa[fa[v][i-1]][i-1];
			bfs_q.push(v);
		}
	}
	
	return;
}

int LCA(int u, int v) {
	if (dep[u] < dep[v]) swap(u, v);
	bfor (i, 19, 0) {
		if (dep[fa[u][i]] >= dep[v])
			u = fa[u][i];
	}
	if (u == v) return u;
	bfor (i, 19, 0) {
		if (fa[u][i] != fa[v][i])
			u = fa[u][i], v = fa[v][i];
	}
	return fa[u][0];
}

int range_LCA(int l, int r) {
	int ret = l;
	cfor (u, l + 1, r) ret = LCA(ret, u);
	return ret;
}

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	cin >> n;
	ofor (i, 1, n) {
		int u, v;
		cin >> u >> v;
		to[u].push_back(v);
		to[v].push_back(u);
	}
	
	build();
	
	cin >> Q;
	while (Q--) {
		int l, r, k;
		cin >> l >> r >> k;
		ans = 0;
		cfor (i, l, r - k + 1) {
			int u = range_LCA(i, i + k - 1);
			if (dep[u] > ans) ans = dep[u];
		}
		cout << ans << endl;
	}
	
	return 0;
}
