#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
struct Edge {
	int u, v, nxt;
} edge[N];
int Tree[N << 2], Head[N], Deep[N], Top[N], Son[N], Siz[N], Fa[N], n, q, ans, E_cnt;
void Build(int id, int l, int r);
int T_Qry1(int id, int l, int r, int x, int y);
int LCA(int x, int y);
void DFS1(int x, int fa);
void DFS2(int x, int top);
void add(int U, int V);
int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	int T1, T2, T3;
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		scanf("%d%d", &T1, &T2);
		add(T1, T2);
		add(T2, T1);
	}
	DFS1(1, 0);
	DFS2(1, 1);
	Build(1, 1, n);
	scanf("%d", &q);
	for (int qi = 1; qi <= q; qi++) {
		scanf("%d%d%d", &T1, &T2, &T3);
		ans = 1;
		for (int i = T1; i + T3 - 1 <= T2; i++) {
			ans = max(ans, Deep[T_Qry1(1, 1, n, i, i + T3 - 1)]);
		}
		printf("%d\n", ans);
	}
	return 0;
}
void Build(int id, int l, int r) {
	if (l == r) {
		Tree[id] = l;
		return;
	}
	int mid = (l + r) >> 1;
	Build(id << 1, l, mid);
	Build(id << 1 | 1, mid + 1, r);
	Tree[id] = LCA(Tree[id << 1], Tree[id << 1 | 1]);
	return;
}
int T_Qry1(int id, int l, int r, int x, int y) {
	if (x <= l && r <= y) {
		return Tree[id];
	}
	int mid = (l + r) >> 1;
	if (y <= mid) {
		return T_Qry1(id << 1, l, mid, x, y);
	}
	if (x > mid) {
		return T_Qry1(id << 1 | 1, mid + 1, r, x, y);
	}
	return LCA(T_Qry1(id << 1, l, mid, x, y), T_Qry1(id << 1 | 1, mid + 1, r, x, y));
}
int LCA(int x, int y) {
	while (Top[x] ^ Top[y]) {
		if (Deep[Top[x]] < Deep[Top[y]]) {
			swap(x, y);
		}
		x = Fa[Top[x]];
	}
	if (Deep[x] > Deep[y]) {
		swap(x, y);
	}
	return x;
}
void DFS1(int x, int fa) {
	Fa[x] = fa;
	Siz[x] = 1;
	Son[x] = -1;
	Deep[x] = Deep[fa] + 1;
	for (int i = Head[x]; i; i = edge[i].nxt) {
		int y = edge[i].v;
		if (y == fa) {
			continue;
		}
		DFS1(y, x);
		Siz[x] += Siz[y];
		if (Son[x] == -1 || Siz[y] > Siz[Son[x]]) {
			Son[x] = y;
		}
	}
}
void DFS2(int x, int top) {
	Top[x] = top;
	if (Son[x] != -1) {
		DFS2(Son[x], top);
	}
	for (int i = Head[x]; i; i = edge[i].nxt) {
		int y = edge[i].v;
		if (y == Fa[x] || y == Son[x]) {
			continue;
		}
		DFS2(y, y);
	}
	return;
}
void add(int U, int V) {
	E_cnt++;
	edge[E_cnt].u = U;
	edge[E_cnt].v = V;
	edge[E_cnt].nxt = Head[U];
	Head[U] = E_cnt;
	return;
}
