#include <bits/stdc++.h>
#define ll int
#define pir pair <ll, ll>
#define mkp make_pair
#define fi first
#define se second
#define pb emplace_back
using namespace std;

void rd(ll &x) {
	char ch; bool f = 0;
	while(!isdigit(ch = getchar()))
		if(ch == '-') f = 1;
	x = ch - '0';
	while(isdigit(ch = getchar()))
		x = (x << 1) + (x << 3) + ch - '0';
	if(f) x = -x;
}

const ll maxn = 1e6 + 10;

ll n, q, dfn[maxn], ti, dep[maxn];
ll eu[maxn], len, eu_dfn[maxn], idfn[maxn];
vector <ll> to[maxn];

void dfs(ll u, ll fa = 0) {
	dfn[u] = ++ti, dep[u] = dep[fa] + 1, idfn[ti] = u;
	eu[++len] = u, eu_dfn[u] = len;
	for(ll v: to[u])
		if(v ^ fa) {
			dfs(v, u);
			eu[++len] = u;
		} 
}

namespace Naive {
	ll st1[20][maxn], st2[20][maxn], st3[20][maxn];
	ll Log[maxn];
	ll ask1(ll l, ll r) {
		ll k = Log[r - l + 1];
		return min(st1[k][l], st1[k][r - (1 << k) + 1]);
	}
	ll ask2(ll l, ll r) {
		ll k = Log[r - l + 1];
		return max(st2[k][l], st2[k][r - (1 << k) + 1]);
	}
	ll ask3(ll l, ll r) {
		ll k = Log[r - l + 1];
		return min(st3[k][l], st3[k][r - (1 << k) + 1]);
	}
	void solve() {
		for(ll i = 1; i <= n; i++)
			st1[0][i] = st2[0][i] = eu_dfn[i];
		for(ll i = 1; i <= len; i++) st3[0][i] = dep[eu[i]];
		for(ll i = 2; i <= len; i++) Log[i] = Log[i >> 1] + 1;
		for(ll i = 1; (1 << i) <= n; i++)
			for(ll j = 1; j + (1 << i) - 1 <= n; j++)
				st1[i][j] = min(st1[i - 1][j], st1[i - 1][j + (1 << i - 1)]),
				st2[i][j] = max(st2[i - 1][j], st2[i - 1][j + (1 << i - 1)]);
		for(ll i = 1; (1 << i) <= len; i++)
			for(ll j = 1; j + (1 << i) - 1 <= len; j++)
				st3[i][j] = min(st3[i - 1][j], st3[i - 1][j + (1 << i - 1)]);
		while(q--) {
			ll l, r, k; rd(l), rd(r), rd(k);
			ll ans = 0;
			for(ll i = l; i + k - 1 <= r; i++)
				ans = max(ans, ask3(ask1(i, i + k - 1), ask2(i, i + k - 1)));
			printf("%d\n", ans);
		}
	}
}

namespace sub_A {
	ll lc[maxn * 10], rc[maxn * 10], tot, rt[maxn];
	struct node { ll pre, suf, mx; bool is; } a[maxn * 10];
	const node operator + (const node &a, const node &b) {
		return (node) { (a.is? b.pre : 0) + a.pre, (b.is? a.suf : 0)
		 + b.suf, max(max(a.mx, b.mx), a.suf + b.pre), a.is & b.is };
	}
	void modify(ll &p, ll q, ll l, ll r, ll x) {
		p = ++tot;
		if(l == r) return a[p] = (node) {1, 1, 1, true}, void();
		lc[p] = lc[q], rc[p] = rc[q]; ll mid = l + r >> 1;
		if(x <= mid) modify(lc[p], lc[q], l, mid, x);
		else modify(rc[p], rc[q], mid + 1, r, x);
		a[p] = a[lc[p]] + a[rc[p]];
	}
	node query(ll p, ll l, ll r, ll ql, ll qr) {
		if(ql <= l && r <= qr) return a[p];
		ll mid = l + r >> 1;
		if(qr <= mid) return query(lc[p], l, mid, ql, qr);
		if(mid < ql) return query(rc[p], mid + 1, r, ql, qr);
		return query(lc[p], l, mid, ql, qr)
		 + query(rc[p], mid + 1, r, ql, qr);
	}
	void solve() {
		rt[n + 1] = 0;
		for(ll i = n; i; i--)
			modify(rt[i], rt[i + 1], 1, n, idfn[i]);
		while(q--) {
			ll l, r, k; rd(l), rd(r), rd(k);
			ll lo = 1, hi = n;
			while(lo <= hi) {
				ll mid = lo + hi >> 1;
				if(query(rt[mid], 1, n, l, r).mx >= k) lo = mid + 1;
				else hi = mid - 1;
			} printf("%d\n", hi);
		}
	}
}

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	rd(n);
	for(ll i = 1; i < n; i++) {
		ll u, v; rd(u), rd(v);
		to[u].pb(v), to[v].pb(u);
	} rd(q), dfs(1); ll _mx = 0;
	for(ll i = 1; i <= n; i++) _mx = max(_mx, (ll) to[i].size());
	if(_mx == 2) sub_A::solve();
	else Naive::solve();
	return 0;
}
