#include <bits/stdc++.h>//来个人保佑这个东西不会炸 
#define fi first
#define endl '\n'
#define il inline
#define se second
#define pb push_back
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 5e5 + 10;
int n, q;
vector<int> G[N];
namespace ST
{
const int lgn = 19;
	int st[N][lgn], dep[N] = {0, 1};
	void dfs(int u, int f)
	{
		dep[u] = dep[st[u][0] = f] + 1;
		for (int i = 1; i < lgn; i++)
			st[u][i] = st[st[u][i - 1]][i - 1];
		for (auto v : G[u])
			if (v != f)
				dfs(v, u);
	}
	int lca(int x, int y)
	{
		if (dep[x] < dep[y]) swap(x, y);
		for (int i = lgn - 1; ~i; i--)
			if (dep[st[x][i]] >= dep[y])
				x = st[x][i];
		if (x == y) return x;
		for (int i = lgn - 1; ~i; i--)
			if (st[x][i] != st[y][i])
				x = st[x][i], y = st[y][i];
		return st[x][0];
	}
}
using namespace ST;
namespace Solve1
{
	int tr[N << 2];
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
	void pushup(int x) { tr[x] = lca(tr[ls(x)], tr[rs(x)]); }
	void build(int u, int l, int r)
	{
		if (l == r)
			return (tr[u] = l, void());
		int mid = l + r >> 1;
		build(ls(u), l, mid);
		build(rs(u), mid + 1, r);
		pushup(u);
	}
	int query(int u, int l, int r, int L, int R)
	{
		if (L <= l && r <= R) return tr[u];
		int mid = l + r >> 1;
		if (L <= mid && mid < R) return lca(query(ls(u), l, mid, L, R), query(rs(u), mid + 1, r, L, R));
		else if (L <= mid) return query(ls(u), l, mid, L, R);
		else return query(rs(u), mid + 1, r, L, R);
	}
}
namespace Solve2
{
	int dfn[N], id;
	void dfs(int u, int f)
	{
		dfn[++id] = u;
		for (auto v : G[u])
			if (v != f)
				dfs(v, u);
	}
	struct Val
	{
		int len, lma, rma, ma;
		Val operator+(const Val &b) const
		{
			Val res;
			res.len = len + b.len;
			res.lma = (lma == len ? len + b.lma : lma);
			res.rma = (b.rma == b.len ? b.len + rma : b.rma);
			res.ma = max(max(ma, b.ma), rma + b.lma);
			return res;
		}
	};
	struct Node
	{
		Val x;
		int l, r;
	} tr[N * 20];
	int rt[N], ncnt;
	void update(int &u, int his, int l, int r, int pos)
	{
		tr[u = ++ncnt] = tr[his];
		if (l == r)
		{
			tr[u].x.lma = tr[u].x.rma = tr[u].x.len = tr[u].x.ma = 1;
			return;
		}
		int mid = l + r >> 1;
		if (pos <= mid) update(tr[u].l, tr[his].l, l, mid, pos);
		else update(tr[u].r, tr[his].r, mid + 1, r, pos);
		tr[u].x = tr[tr[u].l].x + tr[tr[u].r].x;
	}
	Val query(int u, int l, int r, int L, int R)
	{
		if (!u) return {r - l + 1, 0, 0, 0};
		if (L <= l && r <= R) return tr[u].x;
		int mid = l + r >> 1;
		if (L <= mid && mid < R) return query(tr[u].l, l, mid, L, R) + query(tr[u].r, mid + 1, r, L, R);
		else if (L <= mid) return query(tr[u].l, l, mid, L, R);
		else return query(tr[u].r, mid + 1, r, L, R);
	}
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	cin >> n;
	for (int i = 1, u, v; i < n; i++)
		cin >> u >> v, G[u].pb(v), G[v].pb(u);
	int chk = G[1].size() == 1;
	for (int i = 1; i <= n; i++)
		chk &= G[i].size() <= 2;
	if (!chk)
	{
		using namespace Solve1;
		dfs(1, 0), build(1, 1, n);
		cin >> q;
		while (q--)
		{
			int l, r, k, ans = 0;
			cin >> l >> r >> k;
			for (int i = l; i + k - 1 <= r; i++)
				ans = max(ans, dep[query(1, 1, n, i, i + k - 1)]);
			cout << ans << endl;
		}
	}
	else
	{
		using namespace Solve2;
		Solve2::dfs(1, 0);
		for (int i = n; i >= 1; i++)
			update(rt[i], rt[i + 1], 1, n, dfn[i]);
		cin >> q;
		while (q--)
		{
			int l, r, k, ans;
			cin >> l >> r >> k;
			int L = 1, R = n;
			while (L <= R)
			{
				int mid = L + R >> 1;
				if (query(rt[mid], 1, n, l, r).ma >= k) l = mid + 1, ans = mid;
				else r = mid - 1;
			}
			cout << ans << endl;
		}
	}
	return 0;
}
