#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 5e5 + 5;

void read(int &x) {
	x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9')
		ch = getchar();
	while (ch >= '0' && ch <= '9')
		x = x * 10 + ch - '0', ch = getchar();
}

int n, m;
vector<int> e[N];

int p[N] = {0}, dfn[N] = {0}, cur = 0;
int dth[N] = {0};
int st[N][22] = {{0}}; 
void dfs(int x, int pr, int d) {
	p[x] = pr, dfn[x] = ++cur;
	dth[x] = d;
	st[cur][0] = pr;
	for (auto i: e[x])
		if (i != pr)
			dfs(i, x, d + 1);
}
int cmx(int x, int y) {
	return dfn[x] < dfn[y] ? x : y; 
}
int logN[N] = {0};
void init() {
	dfs(1, 0, 1);
	for (int i = 2; i <= n; i++)
		logN[i] = logN[i / 2] + 1;
	for (int j = 1; (1 << j) <= n; j++)
		for (int i = 1; i <= n; i++)
			st[i][j] = cmx(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
}
int qrylca(int x, int y) {
	if (x == 0 || y == 0)
		return x + y;
	if (x == y)
		return x;
	x = dfn[x], y = dfn[y];
	if (x > y)
		swap(x, y);
	x++;
	int k = logN[y - x + 1];
	return cmx(st[x][k], st[y - (1 << k) + 1][k]);
}

namespace SLV1 {
	//区间第 k 大，可持久化线段树
	int tot = 0;
	int val[N << 6] = {0};
	int ls[N << 6] = {0}, rs[N << 6] = {0};
	#define mid ((lx + rx) >> 1)
	void pushup(int x) {
		val[x] = val[ls[x]] + val[rs[x]]; 
	}
	int cpy(int y) {
		int x = ++tot;
		val[x] = val[y], ls[x] = ls[y], rs[x] = rs[y];
		return x;
	}
	void mdf(int &x, int y, int lx, int rx, int pos, int v) {
		x = cpy(y);
		if (lx + 1 == rx) {
			val[x] += v;
			return;
		}
		(pos < mid) ? mdf(ls[x], ls[y], lx, mid, pos, v) : mdf(rs[x], rs[y], mid, rx, pos, v);
		pushup(x);
	}
	int qry(int x, int y, int lx, int rx, int k) {
		if (lx + 1 == rx)
			return lx;
		int sum = val[rs[x]] - val[rs[y]];
		if (k > sum)
			return qry(ls[x], ls[y], lx, mid, k - sum);
		return qry(rs[x], rs[y], mid, rx, k);
	}
	#undef mid 
	int rt[N] = {0};
	void slv() {
		rt[0] = 0;
		for (int i = 1; i <= n; i++) {
			mdf(rt[i], rt[i - 1], 1, n + 1, dth[i], 1);
		}
	//	cout << "tot" << tot << endl;
		read(m);
		for (int i = 1, l, r, k; i <= m; i++) {
			read(l), read(r), read(k);
			printf("%d\n", qry(rt[r], rt[l - 1], 1, n + 1, k));
		}
	}
}

struct Qry {
	int l, r, k;
	Qry (int _l = 0, int _r = 0, int _k = 0) :
		l(_l), r(_r), k(_k) {}
} q[N];

namespace SLV2 {
	//离线维护 
	int ans[5005][5005] = {{0}};
	void initANS() {
		for (int i = 1; i <= n; i++) {
			ans[i][i] = i;
			for (int j = i + 1; j <= n; j++) {
				ans[i][j] = qrylca(ans[i][j - 1], j);
			} 
		}
	}
	
	void slv() {
		initANS();
		for (int i = 1; i <= m; i++) {
			int mx = 0;
			for (int j = q[i].l; j + q[i].k - 1 <= q[i].r; j++)
				mx = max(mx, dth[ans[j][j + q[i].k - 1]]);
			printf("%d\n", mx);
		}
	}
}

namespace SLV3 {
	//线段树
	int val[N << 2] = {0};
	#define ls (x << 1)
	#define rs (x << 1 | 1)
	#define mid ((lx + rx) >> 1)
	void pushup(int x) {
		val[x] = qrylca(val[ls], val[rs]); 
	}
	void build(int x, int lx, int rx) {
		if (lx + 1 == rx) {
			val[x] = lx;
			return;
		}
		build(ls, lx, mid), build(rs, mid, rx);
		pushup(x);
	}
	int qry(int x, int lx, int rx, int l, int r) {
		if (rx <= l || r <= lx)
			return 0;
		if (l <= lx && rx <= r)
			return val[x];
		return qrylca(qry(ls, lx, mid, l, r), qry(rs, mid, rx, l, r));
	}
	#undef ls
	#undef rs
	#undef mid
	 
	void slv() {
		build(1, 1, n + 1);
		for (int i = 1; i <= m; i++) {
			int mx = 0;
			for (int j = q[i].l; j + q[i].k - 1 <= q[i].r; j++)
				mx = max(mx, dth[qry(1, 1, n + 1, j, j + q[i].k)]);
			printf("%d\n", mx);
		}
	}
}

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	read(n);
	bool flg1 = true;
	for (int i = 1, u, v; i < n; i++) {
		read(u), read(v);
		e[u].push_back(v);
		e[v].push_back(u);
		flg1 = flg1 && (e[u].size() <= 2 && e[v].size() <= 2);
	}
//	cout << flg1 << endl;
	init();
	if (flg1 && e[1].size() == 1)
		SLV1::slv();
	else {
		flg1 = true;
		read(m);
		for (int i = 1; i <= m; i++) {
			read(q[i].l), read(q[i].r), read(q[i].k);
			flg1 = flg1 && (q[i].k == q[i].r - q[i].l + 1);
		}
		if (flg1)
			SLV3::slv();
		else
			SLV2::slv();
	}
	return 0;
} 
