#include <bits/stdc++.h>

using namespace std;

const int N = 5e5 + 10, M = 1e6 + 10;

int n, m;
int head[N], to[M], nxt[M], idx;
int sz[N], fa[N], dep[N], son[N], top[N];
int lca[N << 2];

void add(int a, int b)
{
	to[idx] = b, nxt[idx] = head[a], head[a] = idx++;
}

namespace IO
{
	int read()
	{
		int w = 0;
		char ch = getchar();
		while (ch < '0' || ch > '9') ch = getchar();
		while (ch >= '0' && ch <= '9') w = (w << 3) + (w << 1) + ch - '0', ch = getchar();
		return w;
	}
	
	void write(int x)
	{
		if (x > 9) write(x / 10);
		putchar(x % 10 + '0'); 
	}
}

namespace HLD
{
	void dfs1(int u, int father, int depth)
	{
		sz[u] = 1, fa[u] = father, dep[u] = depth;
		for (int i = head[u]; ~i; i = nxt[i])
		{
			int v = to[i];
			if (v == father) continue;
			dfs1(v, u, depth + 1);
			sz[u] += sz[v];
			if (sz[son[u]] < sz[v]) son[u] = v;
		}
	}
	
	void dfs2(int u, int t)
	{
		top[u] = t;
		if (!son[u]) return;
		dfs2(son[u], t);
		for (int i = head[u]; ~i; i = nxt[i])
		{
			int v = to[i];
			if (v == fa[u] || v == son[u]) continue;
			dfs2(v, v);
		}
	}
	
	int lca(int a, int b)
	{
		while (top[a] != top[b])
		{
			if (dep[top[a]] < dep[top[b]]) swap(a, b);
			a = fa[top[a]];
		}
		if (dep[a] < dep[b]) swap(a, b);
		return b;
	}
}

namespace Seg
{
	#define ls (u << 1)
	#define rs (u << 1 | 1)
	#define mid ((l + r) >> 1)
	
	void pushup(int u)
	{
		lca[u] = HLD::lca(lca[ls], lca[rs]);
	}
	
	void build(int u, int l, int r)
	{
		if (l == r)
		{
			lca[u] = r;
			return;
		}
		build(ls, l, mid), build(rs, mid + 1, r);
		pushup(u);
	}
	
	int query(int u, int l, int r, int _l, int _r)
	{
		if (l >= _l && r <= _r) return lca[u];
		if (mid >= _l && mid < _r) return HLD::lca(query(ls, l, mid, _l, _r), query(rs, mid + 1, r, _l, _r));
		if (mid >= _l) return query(ls, l, mid, _l, _r);
		return query(rs, mid + 1, r, _l, _r);
	}
	
	#undef ls
	#undef rs
	#undef mid
}

signed main()
{
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	memset(head, -1, sizeof head);
	n = IO::read();
	for (int i = 1; i < n; i++)
	{
		int a = IO::read(), b = IO::read();
		add(a, b), add(b, a);
	}
	HLD::dfs1(1, 0, 1);
	HLD::dfs2(1, 1);
	Seg::build(1, 1, n);
	m = IO::read();
	while (m--)
	{
		int l = IO::read(), r = IO::read(), k = IO::read();
		int res = 0;
		for (int i = l; i + k - 1 <= r; i++) res = max(res, dep[Seg::query(1, 1, n, i, i + k - 1)]);
		IO::write(res), puts("");
	}
	return 0;
}
