#include <bits/stdc++.h>

using namespace std;
const int N = 5e5 + 5;


inline int read() {
	int flg = 1;
	int ret = 0;
	char ch;
	ch = getchar();
	while (!('0' <= ch && ch <= '9') && !(ch == '-'))
		ch = getchar();
	if (ch == '-') {
		flg = -1;
		ch = getchar();
	}
	do {
		ret = ret * 10 + ch - '0';
		ch = getchar();
	} while ('0' <= ch && ch <= '9');
	return ret;
}

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

int d[N] = {};
int dfn[N], cur = 0;
int rev[N];
int pw[20], lg[N] = {}, st[20][N];
int stmn[20][N], stmx[20][N];

int l[N], r[N], k[N];

void dfs(int x, int pr) {
	dfn[x] = ++cur;
	rev[dfn[x]] = x;
	st[0][dfn[x]] = pr;
	stmn[0][x] = dfn[x];
	stmx[0][x] = dfn[x];
	d[x] = d[pr] + 1;
	for (auto i: e[x])
		if (i != pr)
			dfs(i, x);
}
int sml(int x, int y) {
	if (dfn[x] < dfn[y])
		return x;
	return y;
}
void init_ST() {
	pw[0] = 1;
	for (int i = 1; i < 20; i++)
		pw[i] = pw[i - 1] * 2;
	for (int i = 2; i <= n; i++)
		lg[i] = lg[i / 2] + 1;
	for (int i = 1; i < 20; i++)
		for (int j = 1; j + pw[i] - 1 <= n; j++) {
			st[i][j] = sml(st[i - 1][j], st[i - 1][j + pw[i - 1]]);
			stmn[i][j] = min(stmn[i - 1][j], stmn[i - 1][j + pw[i - 1]]);
			stmx[i][j] = max(stmx[i - 1][j], stmx[i - 1][j + pw[i - 1]]);
		}
}
int lca(int x, int y) {
	if (x == y)
		return x;
	x = dfn[x];
	y = dfn[y];
	if (x > y)
		swap(x, y);
	int s = lg[y - x];
	return sml(st[s][x + 1], st[s][y - pw[s] + 1]);
}
int qrymn(int l, int r) {
	int s = lg[r - l + 1];
	return rev[min(stmn[s][l], stmn[s][r - pw[s] + 1])]; 
}
int qrymx(int l, int r) {
	int s = lg[r - l + 1];
	return rev[max(stmx[s][l], stmx[s][r - pw[s] + 1])];
}

bool chk_isA() {
	int cnt1 = 0;
	for (int i = 1; i <= n; i++)
		if ((int)e[i].size() > 2) {
			return false;
		}
		else if ((int)e[i].size() == 1) {
			cnt1++;
			if (cnt1 > 2)
				return false;
		}
	return true;
}

int ans[N]; //离线 
struct Val {
	int l, r, mx, len;
	Val() {
		l = r = mx = len = 0;
	}
};
Val operator+(Val a, Val b) {
	Val c;
	c.l = a.l;
	if (a.l == a.len)
		c.l = a.len + b.l;
	c.r = b.r;
	if (b.r == b.len)
		c.r = b.len + a.r;
	c.mx = max(max(a.mx, b.mx), a.r + b.l); 
	c.len = a.len + b.len;
	return c;
}
struct SegmentTree {
	int sz;
	vector<Val> val;
	Val ide;
	
	void pushup(int x) {
		val[x] = val[x * 2] + val[x * 2 + 1];
	}
	void mdf(int x, int lx, int rx, int p, int v) {
		if (lx + 1 == rx) {
			if (v == 0)
				val[x].l = val[x].r = val[x].mx = 0;
			else
				val[x].l = val[x].r = val[x].mx = 1;
			return ;
		}
		int m = (lx + rx) / 2;
		if (p < m)
			mdf(x * 2, lx, m, p, v);
		else
			mdf(x * 2 + 1, m, rx, p, v);
		pushup(x);
	}
	Val qry(int x, int lx, int rx, int l, int r) {
		if (l <= lx && rx <= r)
			return val[x];
		if (l >= rx || lx >= r)
			return ide;
		int m = (lx + rx) / 2;
		return qry(x * 2, lx, m, l, r) + qry(x * 2 + 1, m, rx, l, r);
	}
	void build(int x, int lx, int rx) {
		if (lx + 1 == rx) {
			val[x].len = 1;
			return ;
		}
		int m = (lx + rx) / 2;
		build(x * 2, lx, m);
		build(x * 2 + 1, m, rx);
		pushup(x);
	}
	SegmentTree(){}
	SegmentTree(int n) {
		for (sz = 1; sz < n; sz *= 2);
		val.assign(2 * sz, ide);
		build(1, 1, sz + 1);
	}
} sgt;

//整体二分：当前区间[l,r)，dfn在[l,r)中的数为nums，答案在[l,r)中的询问为qrys 
void fz_A(int lx, int rx, vector<int> &nums, vector<int> &qrys) {
	if (qrys.size() == 0)
		return ;
	if (lx + 1 == rx) {
		for (auto i: qrys)
			ans[i] = lx;
		return ;
	}
	int m = (lx + rx) / 2;
	vector<int> num1, num2;
	for (auto i: nums) {
		if (dfn[i] < m) {
			sgt.mdf(1, 1, sgt.sz + 1, i, 0);
			num1.push_back(i);
		}
		else {
			sgt.mdf(1, 1, sgt.sz + 1, i, 1);
			num2.push_back(i); 
		}
	}
	vector<int> q1, q2;
	for (auto i: qrys) {
		Val tmp = sgt.qry(1, 1, sgt.sz + 1, l[i], r[i] + 1);
		if (tmp.mx >= k[i]) //可行，i询问的答案在[m,r)中 
			q2.push_back(i);
		else //不可行 
			q1.push_back(i);
	}
	
	fz_A(lx, m, num1, q1);
	fz_A(m, rx, num2, q2);
}
void slvA() { //性质A:整体二分+线段树 
	sgt = SegmentTree(n);
	vector<int> vnum, vqry;
	for (int i = 1; i <= n; i++)
		vnum.push_back(i);
	for (int i = 1; i <= q; i++)
		vqry.push_back(i);
	fz_A(1, n + 1, vnum, vqry);
	for (int i = 1; i <= q; i++)
		printf("%d\n", ans[i]);
}

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	n = read();
	for (int i = 1, u, v; i < n; i++) {
		u = read();
		v = read();
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(1, 0);
	init_ST();
	
	q = read();
	for (int i = 1; i <= q; i++) {
		l[i] = read();
		r[i] = read();
		k[i] = read();
	}
	
	if (chk_isA()) {
		slvA();
		return 0;
	}
	
	for (int i = 1; i <= q; i++) {
		int mx = -1;
		for (int j = l[i]; j + k[i] - 1 <= r[i]; j++)
			mx = max(mx, d[lca(qrymn(j, j + k[i] - 1), qrymx(j, j + k[i] - 1))]);
		printf("%d\n", mx);
	}
	return 0;
}
