// Lucky_Luo NOIP2024 rp+=inf;
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef double db;
const int N = 5e5 + 7;
int i, j, k, l, r, m, n, idx, cnt, top;
int id[N], dep[N], ans[N], t[N], z[N];
int st[20][N], ST[20][N];
vector <int> d[N];
int read()
{
	int f = 1, x = 0; char ch = getchar();
	while (!isdigit(ch)) 
	{
		if (ch == '-') f = -1;
		ch = getchar();
	}
	while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();
	return f * x;
}
void dfs(int a, int fa)
{
	st[0][id[a]=++idx] = fa, dep[a] = dep[fa] + 1;
	for (int b:d[a]) if (b != fa) dfs(b, a);
}
#define Min(x, y) (id[x] < id[y] ? (x) : (y))
int lca(int x, int y)
{
	if (x == y) return x;
	x = id[x], y = id[y];
	if (x > y) swap(x, y);
	int k = __lg(y-x++);
	return Min(st[k][x], st[k][y-(1<<k)+1]);
}
int ask(int x, int y)
{
	int k = __lg(y-x+1);
	return dep[lca(ST[k][x], ST[k][y-(1<<k)+1])];
}
void prework()
{
	dfs(1, 0);
	for (j=1; j<=__lg(n); j++) for (i=1; i+(1<<j)-1<=n; i++) st[j][i] = Min(st[j-1][i], st[j-1][i+(1<<(j-1))]);
	for (i=1; i<=n; i++) ST[0][i] = i;
	for (j=1; j<=__lg(n); j++) for (i=1; i+(1<<j)-1<=n; i++) ST[j][i] = lca(ST[j-1][i], ST[j-1][i+(1<<(j-1))]);
}
struct node 
{
	int l, r, k, v;
	node(int L=0, int R=0, int K=0, int V=0) : l(L), r(R), k(K), v(V) {}
	bool operator < (const node&x) const {return l < x.l;}
} c[N<<2];
set <node> s[N];
void dsu(int a, int fa)
{
	s[a].insert(node(a, a, 1, 0));
	c[++cnt] = node(a, a, 1, dep[a]);
	for (int b:d[a])
	{
		if (b == fa) continue;
		dsu(b, a);
		if (s[b].size() > s[a].size()) swap(s[a], s[b]);
		for (auto P:s[b])
		{
			int op = 0;
			auto it = s[a].upper_bound(P);
			node K = P, R = it != s[a].end() ? *it : node(), L = it != s[a].begin() ? *prev(it) : node();
			if (R.k && K.r+1 == R.l) op = 1, K.r = R.r, K.k += R.k, s[a].erase(R);
			if (L.k && K.l-1 == L.r) op = 1, K.l = L.l, K.k += L.k, s[a].erase(L);
			if (op) c[++cnt] = {K.l, K.r, K.k, dep[a]};
			s[a].insert(K);
		}
	}
}
int cmpr(node x, node y) {return x.r < y.r;}
int cmpl(node x, node y) {return x.l > y.l;}
void add(int x, int v)
{
	z[++top] = x;
	for (; x; x-=-x&x) t[x] = max(t[x], v);
}
void clr(int x)
{
	for (; x; x-=-x&x) t[x] = 0;
}
int ask(int x)
{
	int res = 0;
	for (; x<=n; x+=-x&x) res = max(res, t[x]);
	return res;
}
void cdq(int l, int r)
{
	if (l == r) return;
	int mid = (l + r) >> 1, i, j = l-1;
	cdq(l, mid), cdq(mid+1, r);
	sort(c+l, c+mid+1, cmpl), sort(c+mid+1, c+r+1, cmpl);
	for (i=mid+1; i<=r; i++) 
	{
		if (c[i].v > 0) continue;
		while (j < mid && c[j+1].l >= c[i].l) if (c[++j].v > 0) add(c[j].k, c[j].v);
		ans[-c[i].v] = max(ans[-c[i].v], ask(c[i].k));
	}
	while (top) clr(z[top--]);
}
signed main()
{
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	n = read();
	for (i=1; i<n; i++) l = read(), r = read(), d[l].pb(r), d[r].pb(l);
	prework();
	cnt = m = read();
	for (i=1; i<=m; i++)
	{
		c[i].l = read(), c[i].r = read(), c[i].k = read(), c[i].v = -i;
		ans[i] = max(ask(c[i].l, c[i].l+c[i].k-1), ask(c[i].r-c[i].k+1, c[i].r));
	}
//	if (n <= 5000 && m <= 5000)
//	{
//		for (i=1; i<=m; i++) for (j=q[i].l; j+q[i].k-1<=q[i].r; j++) ans[i] = max(ans[i], ask(j, j+q[i].k-1));
//		for (i=1; i<=m; i++) printf("%d\n", ans[i]);
//		return 0;
//	}
	dsu(1, 0);
	sort(c+1, c+cnt+1, cmpr);
	cdq(1, cnt);
	for (i=1; i<=m; i++) printf("%d\n", ans[i]);
	return 0;
}
