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

long long read() {
	long long x = 0, k = 1;
	char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') k = -1, c = getchar();
	while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
	return x * k;
}

int MEM;

const int N = 1e5 + 7;

int n, q;
vector <int> to[N];
int ret[N], px[N << 1], dep[N], tot, st[23][N << 1];
int mn[23][N << 1], mx[23][N << 1];
int lzy[N], lzyqwq;
bool pvis[N];

void init() {
	lzyqwq = tot = 0;
	for (int i = 1; i <= n; i ++) {
		to[i].clear();
		pvis[i] = 0;
	}
}

int query(int l, int r) {
	int p = __lg(r - l + 1), q = (1 << p);
	return min(st[p][l], st[p][r - q + 1]);
}

int query2(int l, int r) {
	int p = __lg(r - l + 1), q = (1 << p);
	return min(mn[p][l], mn[p][r - q + 1]);
}

int query3(int l, int r) {
	int p = __lg(r - l + 1), q = (1 << p);
	return max(mx[p][l], mx[p][r - q + 1]);
}

void dfs(int u, int fa, int d) {
	lzy[++ lzyqwq] = u;
	dep[u] = d;
	ret[u] = ++ tot;
	px[tot] = d;
	for (int v : to[u]) {
		if (v == fa) continue;
		dfs(v, u, d + 1);
		px[++ tot] = d;
	}
}

struct Seg {
	int lx, rx, val, tg;
	bool flgL, flgR;
} tr[N << 5];

int wjc, rt[N];

void upd(int x) {
	if (!tr[x].flgL) {
		tr[++ wjc] = tr[tr[x].lx];
		tr[wjc].flgL = tr[wjc].flgR = 0;
		tr[x].flgL = 1;
		tr[x].lx = wjc;
	}
	if (!tr[x].flgR) {
		tr[++ wjc] = tr[tr[x].rx];
		tr[wjc].flgL = tr[wjc].flgR = 0;
		tr[x].flgR = 1;
		tr[x].rx = wjc;
	}
} 

void hard(int x, int p) {
	tr[x].val += p;
	tr[x].tg += p;
}

void pushDown(int x, int l, int r) {
	upd(x);
	if (tr[x].tg) {
		hard(tr[x].lx, tr[x].tg);
		hard(tr[x].rx, tr[x].tg);
	}
}

void pushUp(int x) {
	tr[x].val = max(tr[tr[x].lx].val, tr[tr[x].rx].val);
}

void update(int tx, int &x, int l, int r, int L, int R, int p) {
	if (!x) {
		x = ++ wjc;
		tr[x] = tr[tx];
		tr[x].flgL = tr[x].flgR = 0;
	}
	if (L <= l && r <= R) {
		hard(x, p);
		return ;
	}
	pushDown(tx, l, r);
	pushDown(x, l, r);
	int mid = l + r >> 1;
	if (L <= mid) update(tr[tx].lx, tr[x].lx, l, mid, L, R, p);
	if (mid < R)  update(tr[tx].rx, tr[x].rx, mid + 1, r, L, R, p);
	pushUp(x);
}

long long query(int &x, int l, int r, int L, int R) {
	if (L > n || R < 1) return 0;
	if (!x) x = ++ wjc;
	if (L <= l && r <= R) 
		return tr[x].val;
	pushDown(x, l, r);
	int mid = l + r >> 1;
	long long res = 0;
	if (L <= mid) res = query(tr[x].lx, l, mid, L, R);
	if (mid < R)  res = max(res, query(tr[x].rx, mid + 1, r, L, R));
	return res;
}

void out(int x, int l, int r) {
	if (l == r) {
		return ;
	}
	int mid = l + r >> 1;
	pushDown(x, l, r);
	printf("[%d, %d] val = %d\n", l, r, tr[x].val);
	printf("[%d, %d] -> [%d, %d] --- %d -> %d\n", l, r, l, mid, x, tr[x].lx);
	printf("[%d, %d] -> [%d, %d] --- %d -> %d\n", l, r, mid + 1, x, tr[x].rx);
	out(tr[x].lx, l, mid);
	out(tr[x].rx, mid + 1, r);
}

namespace DSU {
	int fa[N];
	void init() {
		for (int i = 1; i <= n; i ++)	
			fa[i] = i;
	}
	int find(int x) {
		return (x == fa[x] ? x : (fa[x] = find(fa[x])));
	}
	void merge(int i, int j) {
		int x = find(i), y = find(j);
		if (x == y) return ;
		fa[y] = x;
	}
}

void solve() {
	n = read();
	init();
	for (int i = 1, u, v; i < n; i ++) {
		u = read(), v = read();
		to[u].push_back(v);
		to[v].push_back(u);
	}
	dfs(1, 0, 1);
	for (int i = 1; i <= 2 * n; i ++)
		st[0][i] = px[i];
	for (int j = 1; j <= 20; j ++)
		for (int i = 1; i <= 2 * n - (1 << j) + 1; i ++) 
			st[j][i] = min(st[j - 1][i], st[j - 1][i + (1 << (j - 1))]);
	for (int i = 1; i <= n; i ++)
		mn[0][i] = mx[0][i] = ret[i];
	for (int j = 1; j <= 20; j ++)
		for (int i = 1; i <= n - (1 << j) + 1; i ++) {
			mn[j][i] = min(mn[j - 1][i], mn[j - 1][i + (1 << (j - 1))]);
			mx[j][i] = max(mx[j - 1][i], mx[j - 1][i + (1 << (j - 1))]);
		}
	q = read();
	if (n <= 5000 && q <= 5000) {
		while (q --) {
			int l = read(), r = read(), k = read();
			int res = 0;
			for (int i = l; i <= r - k + 1; i ++) {
				int wjcwjcl = query2(i, i + k - 1);
				int wjcwjcr = query3(i, i + k - 1);
				res = max(res, query(wjcwjcl, wjcwjcr));
			}
			cout << res << '\n';
		}
	} else {
		rt[n + 1] = 1;
		DSU::init();
		for (int id = n; id >= 1; id --) {
			int i = lzy[id];
			pvis[i] = 1;
			if (i > 1 && pvis[i - 1])
				DSU::merge(i - 1, i);
			int len = query(rt[i + 1], 1, n, i + 1, i + 1) + 1;
			if (pvis[i + 1] == 0)
				len = 1;
			update(rt[i + 1], rt[i], 1, n, DSU::find(i), i, len);
		}
		while (q --) {
			int l = read(), r = read(), k = read();
			int lx = 1, rx = n, ans = 0;
			while (lx <= rx) {
				int mid = lx + rx >> 1;
				if (query(rt[mid], 1, n, l, r - k + 1) >= k) {
					ans = mid;
					lx = mid + 1;
				} else {
					rx = mid - 1;
				}
			}
			cout << ans << '\n';
		}
	}
}

int LST;

signed main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
//	cerr << (&LST - &MEM) / 1048576.0 << '\n';
	int t = 1;
	while (t --)
		solve();
	return 0;
}
/*
//freopen("edit.in", "r", stdin);
//freopen("edit.out", "w", stdout);
//freopen("edit.in", "r", stdin);
//freopen("edit.out", "w", stdout);
//freopen("edit.in", "r", stdin);
//freopen("edit.out", "w", stdout);
//freopen("edit.in", "r", stdin);
//freopen("edit.out", "w", stdout);
//freopen("edit.in", "r", stdin);
//freopen("edit.out", "w", stdout);
//freopen("edit.in", "r", stdin);
//freopen("edit.out", "w", stdout);
*/

