#include <bits/stdc++.h>
using namespace std;

constexpr int N = 5e5 + 5, M = 4e7 + 5;

int t, n, q, md;

array<vector<int>, N> G;
array<int, N> ql, qr, qk;
array<int, N> ans, p;

struct Seg
{
	int l, r;
	Seg() = default;
	Seg(int l, int r): l(l), r(r){}
	bool operator<(const Seg& tt) const noexcept
	{
		return (l != tt.l ? l < tt.l : r < tt.r);
	}
	bool operator==(const Seg& tt) const noexcept
	{
		return (l == tt.l && r == tt.r);
	}
};

map<Seg, int> mp;
array<set<Seg>, N> f;
array<int, N> dep;

inline bool cmp(int x, int y)
{
	return f[x].size() > f[y].size();
}

void dfs(int u, int fa)
{
	dep[u] = dep[fa] + 1;
	md = max(md, dep[u]);
	vector<int> son;
	for (auto &j : G[u])
	{
		if (j != fa)
		{
			dfs(j, u);
			son.emplace_back(j);
		}
	}
	if (!son.size())
	{
		f[u].emplace(u, u);
		mp[Seg(u, u)] = dep[u];
		return;
	}
	sort(son.begin(), son.end(), cmp);
	f[u].swap(f[son[0]]);
	f[son[0]].clear();
	for (int i = 1; i < son.size(); i++)
	{
		int j = son[i];
		for (auto &x : f[j])
		{
			int l = x.l, r = x.r;
			f[u].emplace(l, r);
			auto it = f[u].find(Seg(l, r));
			if (it != f[u].begin() && prev(it)->r == l - 1)
			{
				int nl = prev(it)->l;
				f[u].erase(prev(it));
				f[u].erase(Seg(l, r));
				it = f[u].emplace(nl, r).first;
				mp[Seg(nl, r)] = max(mp[Seg(nl, r)], dep[u]);
				l = nl;
			}
			if (next(it) != f[u].end() && next(it)->l == r + 1)
			{
				int nr = next(it)->r;
				f[u].erase(next(it));
				f[u].erase(Seg(l, r));
				f[u].emplace(l, nr);
				mp[Seg(l, nr)] = max(mp[Seg(l, nr)], dep[u]);
			}
		}
		f[j].clear();
	}
	int l = u, r = u;
	f[u].emplace(l, r);
	auto it = f[u].find(Seg(l, r));
	mp[Seg(l, r)] = dep[u];
	if (it != f[u].begin() && prev(it)->r == l - 1)
	{
		int nl = prev(it)->l;
		f[u].erase(prev(it));
		f[u].erase(Seg(l, r));
		it = f[u].emplace(nl, r).first;
		mp[Seg(nl, r)] = max(mp[Seg(nl, r)], dep[u]);
		l = nl;
	}
	if (next(it) != f[u].end() && next(it)->l == r + 1)
	{
		int nr = next(it)->r;
		f[u].erase(next(it));
		f[u].erase(Seg(l, r));
		f[u].emplace(l, nr);
		mp[Seg(l, nr)] = max(mp[Seg(l, nr)], dep[u]);
	}
}

class SegmentTree
{
public:
	int idx;
	struct Node
	{
		int ls, rs, maxn;
	};
	array<Node, M> tr;
	int update(int u, int l, int r, int x, int v)
	{
		int nu = ++idx;
		tr[nu] = tr[u];
		if (l == r)
		{
			tr[nu].maxn = max(tr[nu].maxn, v);
			return nu;
		}
		int mid(l + r >> 1);
		if (x <= mid) tr[nu].ls = update(tr[u].ls, l, mid, x, v);
		else tr[nu].rs = update(tr[u].rs, mid + 1, r, x, v);
		tr[nu].maxn = max(tr[tr[nu].rs].maxn, tr[tr[nu].ls].maxn);
		return nu;
	}
	inline int qmax(int u, int l, int r, int &nl, int &nr)
	{
		if (!u) return 0;
		if (l >= nl && r <= nr) return tr[u].maxn;
		int mid(l + r >> 1), res(0);
		if (nl <= mid) res = qmax(tr[u].ls, l, mid, nl, nr);
		if (nr > mid && tr[tr[u].rs].maxn > res) res = max(res, qmax(tr[u].rs, mid + 1, r, nl, nr));
		return res;
	}
}sgt;

array<int, N> rt1, rt3;

inline bool cmp2(int x, int y)
{
	return qr[x] < qr[y];
}

array<vector<pair<int, int>>, N> ve;

namespace Solver2
{
	vector<array<int, 20>> faf;
	array<int, N> dfn, ra;
	int id;
	void dfs(int u, int fa)
	{
		dfn[u] = ++id;
		ra[id] = u;
		faf[u][0] = fa;
		for (auto &j : G[u])
		{
			if (j ^ fa)
			{
				dfs(j, u);
			}
		}
	}
	class SegmentTree
	{
	public:
		int idx;
		struct Node
		{
			int l, r, maxn, minn;
		};
		array<Node, N << 2> tr;
		void build(int u, int l, int r)
		{
			tr[u] = { l, r, dfn[l], dfn[l] };
			if (l == r) return;
			int mid = l + r >> 1;
			build(u << 1, l, mid);
			build(u << 1 | 1, mid + 1, r);
			tr[u].minn = min(tr[u << 1].minn, tr[u << 1 | 1].minn);
			tr[u].maxn = max(tr[u << 1].maxn, tr[u << 1 | 1].maxn);
		}
		inline int qmin(int u, int l, int r)
		{
			if (tr[u].l >= l and tr[u].r <= r)
			{
				return tr[u].minn;
			}
			int mid = tr[u].l + tr[u].r >> 1, res = (int)1e9;
			if (l <= mid) res = qmin(u << 1, l, r);
			if (r > mid) res = min(res, qmin(u << 1 | 1, l, r));
			return res;
		}
		inline int qmax(int u, int l, int r)
		{
			if (tr[u].l >= l and tr[u].r <= r)
			{
				return tr[u].maxn;
			}
			int mid = tr[u].l + tr[u].r >> 1, res = 0;
			if (l <= mid) res = qmax(u << 1, l, r);
			if (r > mid) res = max(res, qmax(u << 1 | 1, l, r));
			return res;
		}
	}sgt;
	inline int LCA(int u, int v)
	{
		if (u == v) return u;
		if (dep[u] < dep[v]) swap(u, v);
		int k = dep[u] - dep[v], c = 0;
		while (k)
		{
			if (k & 1) u = faf[u][c];
			c++;
			k >>= 1;
		}
		if (u == v) return u;
		for (int i = 19; i >= 0; i--) if (faf[u][i] ^ faf[v][i]) u = faf[u][i], v = faf[v][i];
		return faf[u][0];
	}
	void solve()
	{
		faf.resize(n + 1);
		dfs(1, 0);
		for (int j = 1; j < 20; j++)
		{
			for (int i = 1; i <= n; i++) faf[i][j] = faf[faf[i][j - 1]][j - 1];
		}
		sgt.build(1, 1, n);
		for (int i = 1; i <= q; i++)
		{
			int l = ql[i], r = qr[i], k = qk[i];
			int x = ra[sgt.qmin(1, l, r)], y = ra[sgt.qmax(1, l, r)];
			cout << dep[LCA(x, y)] << "\n";
		}
	}
};

int main()
{
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	ios::sync_with_stdio(0), cin.tie(0);
	sgt.tr[0].maxn = 0;
	cin >> n;
	for (int i = 1; i < n; i++)
	{
		int u, v;
		cin >> u >> v;
		G[u].emplace_back(v), G[v].emplace_back(u);
	}
	dfs(1, 0);
	bool tag = 1;
	cin >> q;
	for (int i = 1; i <= q; i++)
	{
		cin >> ql[i] >> qr[i] >> qk[i];
		p[i] = i;
		tag &= (qk[i] == qr[i] - ql[i] + 1);
	}
	if (tag)
	{
		Solver2::solve();
		return 0;
	}
	for (auto &x : mp)
	{
		int l = x.first.l, r = x.first.r, k = x.second;
		ve[k].emplace_back(l, r);
	}
	for (int i = md; i >= 1; i--)
	{
		rt1[i] = rt1[i + 1];
		for (auto &x : ve[i])
		{
			int l = x.first, r = x.second;
			rt1[i] = sgt.update(rt1[i], 1, n, l, r);
		}
		rt3[i] = rt3[i + 1];
		for (auto &x : ve[i])
		{
			int l = x.first, r = x.second;
			rt3[i] = sgt.update(rt3[i], 1, n, l, r - l + 1);
		}
	}
	int xt = 1;
	for (int i = 1; i <= q; i++)
	{
		int j = p[i];
		int l = ql[j], r = qr[j], kk = qk[j];
		int ll = 1, rr = md, ret = -1;
		int lim(r - kk + 1);
		int gg(l - 1);
		while (ll <= rr)
		{
			int res(0);
			int mid(ll + rr >> 1);
			if (l > 1) res = sgt.qmax(rt1[mid], 1, n, xt, gg) - l + 1;
			if (res < kk) res = sgt.qmax(rt3[mid], 1, n, l, lim);
			if (res >= kk) ret = mid, ll = mid + 1;
			else rr = mid - 1;
		}
		cout << ret << "\n";
	}
	return 0;
}
