#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define LLL __int128
#define pii pair<int, int>
#define fi first
#define se second
#define mkp make_pair
#define sz(x) (int)x.size()
#define pb push_back
using namespace std;

int read() {
	int s = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
	while (ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
	return s * f;
}

template <typename T>
void chkmn(T &x, T y) { x = x < y ? x : y;}
template <typename T>
void chkmx(T &x, T y) { x = y < x ? x : y;}

const int MAXN = 500005;

int n, m;
vector<int> e[MAXN];
int dep[MAXN], fa[MAXN], sz[MAXN], son[MAXN], top[MAXN];
int dfn[MAXN], rnk[MAXN], tim = 0;
vector<int> p[MAXN];

struct Node {
	int l, r, k, id;
} qry[MAXN], q1[MAXN], q2[MAXN];

void dfs(int x) {
	dep[x] = dep[fa[x]] + 1, son[x] = 0, sz[x] = 1;
	for (int y : e[x]) {
		if (y == fa[x]) continue;
		fa[y] = x, dfs(y), sz[x] += sz[y];
		if (sz[son[x]] < sz[y]) son[x] = y;
	}
}

void cut(int x, int tp) {
	top[x] = tp, dfn[x] = ++tim, rnk[tim] = x;
	if (son[x]) cut(son[x], tp);
	for (int y : e[x])
		if (y != fa[x] && y != son[x])
			cut(y, y);
}

int lca(int u, int v) {
	if (top[u] == top[v]) return dep[u] > dep[v] ? v : u;
	return dep[top[u]] < dep[top[v]] ? lca(u, fa[top[v]]) : lca(fa[top[u]], v);
}

namespace ST {

#define pw(i) (1 << (i))
int mn[MAXN][20], mx[MAXN][20], lg[MAXN];

void init() {
	lg[0] = -1;
	for (int i = 1; i <= n; i++) mn[i][0] = mx[i][0] = dfn[i], lg[i] = lg[i >> 1] + 1;
	for (int j = 1; j <= 19; j++)
		for (int i = 1; i + pw(j) - 1 <= n; i++)
			mn[i][j] = min(mn[i][j - 1], mn[i + pw(j - 1)][j - 1]), mx[i][j] = max(mx[i][j - 1], mx[i + pw(j - 1)][j - 1]);
}

int qry(int l, int r) {
	int i = lg[r - l + 1];
	int x = rnk[min(mn[l][i], mn[r - pw(i) + 1][i])], y = rnk[max(mx[l][i], mx[r - pw(i) + 1][i])];
	return dep[lca(x, y)];
}

}

int ans[MAXN];
int num = 0;

namespace SGT {
	#define ls (p << 1)
	#define rs (p << 1 | 1)
	#define mid ((l + r) >> 1)
	int id[MAXN];
	struct Node {
		int ans, vl, vr, cl, cr, cov;
		friend Node operator + (const Node &x, const Node &y) {
			num++;
			Node ans;
			ans.ans = max(x.ans, y.ans), ans.vl = x.vl, ans.vr = y.vr, ans.cov = x.cov && y.cov && (x.vl == y.vl);
			if (x.vr == y.vl) chkmx(ans.ans, x.cr + y.cl);
			ans.cl = x.cl + (y.vl == x.vl && x.cov) * y.cl, ans.cr = y.cr + (x.vr == y.vr && y.cov) * x.cr;
			return ans;
		}
	} tr[MAXN << 2];
	void build(int l, int r, int p) {
		if (l == r) {
			tr[p] = (Node){1, 1, 1, 1, 1, 1}, id[l] = p;
			return ;
		}
		build(l, mid, ls), build(mid + 1, r, rs);
		tr[p] = tr[ls] + tr[rs];
	}
	void mdf(int x, int v) {
		int p = id[x];
		tr[p] = (Node){v > 0, v, v, v > 0, v > 0, 1};
		while (p > 1) p >>= 1, tr[p] = tr[ls] + tr[rs];
	}
	Node qry(int l, int r, int p, int x, int y) {
		if (x <= l && r <= y) return tr[p];
		if (y <= mid) return qry(l, mid, ls, x, y);
		if (mid < x) return qry(mid + 1, r, rs, x, y);
		return qry(l, mid, ls, x, y) + qry(mid + 1, r, rs, x, y);
	}
	int qry(int l, int r) {
		Node ans = qry(1, n, 1, l, r);
		return ans.ans;
	}
	#undef mid
}

void dfs2(int x, int v) {
	SGT::mdf(x, v);
	for (int y : e[x])
		if (y != fa[x]) dfs2(y, v);
}

void del(int x) {
	SGT::mdf(x, -x);
	for (int y : e[x])
		if (y != fa[x] && y != son[x])
			dfs2(y, y);
}

void add(int x) {
	SGT::mdf(x, top[x]);
	for (int y : e[x])
		if (y != fa[x] && y != son[x])
			dfs2(y, top[x]);
}

void solve(int l, int r, int ql, int qr) {
	if (ql > qr) return ;
	if (l == r) {
		for (int i = ql; i <= qr; i++) ans[qry[i].id] = l;
		return ;
	}
	int mid = (l + r) >> 1;
	for (int i = l; i <= mid; i++)
		for (int x : p[i]) del(x);
	int c1 = 0, c2 = 0;
	for (int i = ql; i <= qr; i++) {
		if (SGT::qry(qry[i].l, qry[i].r) >= qry[i].k) q2[++c2] = qry[i];
		else q1[++c1] = qry[i];
	}
	int tmp = ql;
	for (int i = 1; i <= c1; i++) qry[tmp++] = q1[i];
	for (int i = 1; i <= c2; i++) qry[tmp++] = q2[i];
	solve(mid + 1, r, ql + c1, qr);
	for (int i = mid; i >= l; i--)
		for (int x : p[i]) add(x);
	solve(l, mid, ql, ql + c1 - 1);
}

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	n = read();
	for (int i = 1; i < n; i++) {
		int u = read(), v = read();
		e[u].pb(v), e[v].pb(u);
	}
	dfs(1), cut(1, 1);
	for (int i = 1; i <= n; i++) p[dep[i]].pb(i);
	int mx = 0, q = read();
	for (int i = 1; i <= n; i++) chkmx(mx, dep[i]);
	ST::init();
	for (int i = 1; i <= q; i++) {
		int l = read(), r = read(), k = read();
		if (k == r - l + 1) ans[i] = ST::qry(l, r);
		else qry[++m] = (Node){l, r, k, i};
	}
	SGT::build(1, n, 1);
//	cerr << 1.0 * clock() / CLOCKS_PER_SEC << endl;
	solve(1, mx, 1, m);
//	cerr << 1.0 * clock() / CLOCKS_PER_SEC << endl;
//	cerr << num << endl;
	for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
	return 0;
}
