#include<bits/stdc++.h>
#define mn(x, y) (dfn[x] < dfn[y] ? x : y) 
#define pb emplace_back
using namespace std;

const int N = 5e5 + 7; 
int i, j, k, n, m, u, v, q;
int dep[N];
int du[N], st[20][N], id, dfn[N], f[20][N];
vector<int> d[N];
struct qry {
	int x, y, k;
	#define x(i) qr[i].x
	#define y(i) qr[i].y
	#define k(i) qr[i].k
} qr[N];

void dfs(int u, int fu) {
	st[0][dfn[u] = ++id] = fu; dep[u] = dep[fu] + 1;
	for(int v : d[u]) if(v != fu) dfs(v, u), du[u]++;
}

int lca(int x, int y) {
	if(x == y) return x;
	if((x = dfn[x]) > (y = dfn[y])) swap(x, y);
	int k = __lg(y - x++);
	return mn(st[k][x], st[k][y-(1<<k)+1]);
}

int Lca(int x, int y) {
	int k = __lg(y - x + 1);
	return lca(f[k][x], f[k][y-(1<<k)+1]);
}

struct nd {
	int l, r, s;
	#define l(p) tr[p].l
	#define r(p) tr[p].r
	#define s(p) tr[p].s
} tr[N<<5];
#define mid (l + r >> 1)
int rt[N], P;

void add(int &p, int pp, int x, int l = 1, int r = n) {
	tr[p=++P] = tr[pp], s(p)++;
	if(l == r) return;
	x <= mid ? add(l(p), l(pp), x, l, mid) : add(r(p), r(pp), x, mid+1, r);
}

int ask(int pp, int p, int k, int l = 1, int r = n) {
	if(l == r) return l; int t = s(r(p)) - s(r(pp));
	return t >= k ? ask(r(pp), r(p), k, mid + 1, r) : ask(l(pp), l(p), k-t, l, mid);
}

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	scanf("%d", &n);
	for(i = 1; i < n; i++) {
		scanf("%d%d", &u, &v);
		d[u].pb(v), d[v].pb(u);
	}
	dfs(1, 1);
	scanf("%d", &q);
	for(i = 1; i <= q; i++) scanf("%d%d%d", &x(i), &y(i), &k(i));
	int lian = 1;
	for(i = 1; i <= n; i++) lian &= du[i] <= 1;
	if(lian) {
		for(i = 1; i <= n; i++) add(rt[i], rt[i-1], dep[i]);
		for(i = 1; i <= q; i++) {
			printf("%d\n", ask(rt[x(i)-1], rt[y(i)], k(i)));
		}
		return 0;
	}
	for(j = 1; j <= __lg(n); j++) for(i = 1; i + (1 << j) - 1 <= n; i++)
		st[j][i] = mn(st[j-1][i], st[j-1][i+(1<<j-1)]);
	for(i = 1; i <= n; i++) f[0][i] = i;
	for(j = 1; j <= __lg(n); j++) for(i = 1; i + (1 << j) - 1 <= n; i++) 
		f[j][i] = lca(f[j-1][i], f[j-1][i+(1<<j-1)]);//, cout << " " << i << " " << j << " " << f[j][i] << "\n";
	for(i = 1; i <= q; i++) {
		int res = 0;
		for(j = x(i); j + k(i) - 1 <= y(i); j++) {
//			cout << j << " " << j + k(i) - 1 << " " << Lca(j, j + k(i) - 1) << "\n";
			res = max(res, dep[Lca(j, j + k(i) - 1)]);
		}
		printf("%d\n", res);
	}
	return 0;
}
