#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define umap unordered_map
#define empb emplace_back
#define _log2(x) (63-__builtin_clzll(x))

const ll MAXN = 5e5 + 5;

ll n, p[23][MAXN], d[MAXN], dpe = 0, q, st[23][MAXN];
vector<ll> e[MAXN];

void bdt(ll x, ll pr, ll dpt) {
	p[0][x] = pr;
	d[x] = dpt;
	dpe = max(dpe, dpt);
	for (ll i : e[x]) {
		if (i == pr) {
			continue;
		}
		bdt(i, x, dpt + 1);
	}
}

ll fnd(ll l, ll r) {
	if (l == r) {
		return l;
	}
	ll len = r - l + 1;
	ll k = _log2(len);
	if ((1 << k) == len) {
		--k;
	}
	if (st[k][l] <= st[k][r - (1 << k) + 1]) {
		return fnd(l, l + ((1 << k) - 1));
	} else {
		return fnd(r - (1 << k) + 1, r);
	}
}
ll qry(ll l, ll r) {
	ll len = r - l + 1;
	ll k = _log2(len);
	return min(st[k][l], st[k][r - (1 << k) + 1]);
}
void slv_lnk() {
	for (ll i = 1; i <= n; ++i) {
		st[0][i] = d[i];
	}
	for (ll k = 1; k <= 21; ++k) {
		for (ll i = 1; i + (1 << k) - 1 <= n; ++i) {
			st[k][i] = min(st[k - 1][i], st[k - 1][i + (1 << (k - 1))]);
		}
	}
	while (q--) {
		ll l, r, k;
		cin >> l >> r >> k;
		while (1) {
			ll cur = fnd(l, r);
			bool banl = cur - 1 - l + 1 < k;
			bool banr = r - cur - 1 + 1 < k;
			if (banl && banr) {
				cout << d[cur] << endl;
				break;
			}
			if (!banl && banr) {
				r = cur - 1;
			} else if (!banr && banl) {
				l = cur + 1;
			} else {
				if (qry(l, cur - 1) <= qry(cur + 1, r)) {
					r = cur - 1;
				} else {
					l = cur + 1;
				}
			}
		}
	}
}

ll LCA(ll x, ll y) {
	if (d[x] < d[y]) {
		swap(x, y);
	}
	if (d[x] > d[y]) {
		for (ll k = 21; k >= 0; --k) {
			if (d[p[k][x]] >= d[y]) {
				x = p[k][x];
			}
		}
	}
	if (x == y) {
		return x;
	}
	for (ll k = 21; k >= 0; --k) {
		if (p[k][x] != p[k][y]) {
			x = p[k][x];
			y = p[k][y];
		}
	}
	return p[0][x];
}
void bruteforce() {
	for (ll k = 1; k <= 21; ++k) {
		for (ll i = 1; i <= n; ++i) {
			p[k][i] = p[k - 1][p[k - 1][i]];
		}
	}
	while (q--) {
		ll l, r, k, ans = 0;
		cin >> l >> r >> k;
		for (ll i = l; i + k - 1 <= r; ++i) {
			ll j = i + k - 1;
			ll curlca = i;
			for (ll h = i + 1; h <= j; ++h) {
				curlca = LCA(curlca, h);
			}
			ans = max(ans, d[curlca]);
		}
		cout << ans << endl;
	}
}

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	cin >> n;
	for (ll i = 1, u, v; i < n; ++i) {
		cin >> u >> v;
		e[u].empb(v);
		e[v].empb(u);
	}
	bdt(1, 0, 1);
	cin >> q;
	if (dpe == n) {
		slv_lnk();
		return 0;
	}
	bruteforce();
	return 0;
}













































