#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
using namespace std;

#define MAXN 1000006
#define MAXL 22
#define ls (p << 1)
#define rs (p << 1 | 1)

using pii = array<int, 2>;

int n, q;

struct Edge
{
	int u, v, w;
} es[MAXN];

bool cmp(Edge a, Edge b)
{
	return a.w > b.w;
}

vector<int> e[MAXN];
int dg[MAXN];

int dep[MAXN], dfn[MAXN], rnk[MAXN];

pii ch[MAXN];
int cnt = 0;

void dfs1(int p, int f)
{
	dep[p] = dep[f] + 1;
	dfn[p] = ++cnt;
	rnk[cnt] = p;
	for (int u : e[p])
	{
		if (u == f)
		{
			continue;
		}
		dfs1(u, p);
	}
}

int ff[MAXN];

int find(int x)
{
	return x == ff[x] ? x : ff[x] = find(ff[x]);
}

int kdp[MAXN];
int fa[MAXN][MAXL];
int st[2][MAXN][MAXL];
int lg[MAXN];

inline int qstl(int l, int r)
{
	if (l == r)
	{
		return st[0][l][0];
	}
	int g = lg[r - l];
	return min(st[0][l][g], st[0][r - (1 << g) + 1][g]);
}

inline int qstu(int l, int r)
{
	if (l == r)
	{
		return st[1][l][0];
	}
	int g = lg[r - l];
	return max(st[1][l][g], st[1][r - (1 << g) + 1][g]);
}

inline int klca(int u, int v)
{
	if (u == v)
	{
		return u;
	}
	if (kdp[u] < kdp[v])
	{
		swap(u, v);
	}
	for (int k = MAXL - 1; ~k; k--)
	{
		if (kdp[fa[u][k]] >= kdp[v])
		{
			u = fa[u][k];
		}
	}
	if (u == v)
	{
		return u;
	}
	for (int k = MAXL - 1; ~k; k--)
	{
		if (fa[u][k] != fa[v][k])
		{
			u = fa[u][k];
			v = fa[v][k];
		}
	}
	return fa[u][0];
}

struct Tree
{
	int l, r, a, s;
} t[MAXN << 2];

Tree merge(Tree a, Tree b)
{
	return Tree{
		a.l + (a.s ? b.l : 0),
		b.r + (b.s ? a.r : 0),
		max({a.a, b.a, a.r + b.l}),
		a.s && b.s
	};
}

void pushup(int p)
{
	t[p] = merge(t[ls], t[rs]);
}

void modi(int p, int l, int r, int q, int v)
{
	if (l == r)
	{
		t[p] = {v, v, v, v};
		return;
	}
	int mid = (l + r) >> 1;
	if (mid >= q)
	{
		modi(ls, l, mid, q, v);
	}
	else
	{
		modi(rs, mid + 1, r, q, v);
	}
	pushup(p);
}

Tree qry(int p, int l, int r, int ql, int qr)
{
	if (ql <= l && r <= qr)
	{
		return t[p];
	}
	int mid = (l + r) >> 1;
	Tree res = {0, 0, 0, 1};
	if (mid >= ql)
	{
		res = qry(ls, l, mid, ql, qr);
	}
	if (mid < qr)
	{
		res = merge(res, qry(rs, mid + 1, r, ql, qr));
	}
	return res;
}

struct ZTEF
{
	int l, r, v, p, t;
};

int out1[MAXN];

void ztef(vector<ZTEF> &q, int l, int r)
{
	if (q.empty())
	{
		return;
	}
	if (l == r)
	{
		for (ZTEF c : q)
		{
			if (c.t == 1)
			{
				// cout << ' ' << l << ' ' << c.p << endl;
				out1[c.p] = l;
			}
		}
		return;
	}
	vector<ZTEF> q1, q2;
	int mid = (l + r) >> 1;
	for (ZTEF c : q)
	{
		if (c.t == 0)
		{
			if (c.v <= mid)
			{
				q1.push_back(c);
			}
			else
			{
				// cout << mid << ' ' << c.l << endl;
				modi(1, 1, n, c.l, 1);
				q2.push_back(c);
			}
		}
		else
		{
			int s = qry(1, 1, n, c.l, c.r).a;
			// cout << mid << ' ' << c.l << ' ' << c.r << ' ' << s << endl;
			if (s < c.v)
			{
				q1.push_back(c);
			}
			else
			{
				q2.push_back(c);
			}
		}
	}
	ztef(q1, l, mid);
	for (ZTEF c : q)
	{
		if (c.t == 0 && c.v > mid)
		{
			modi(1, 1, n, c.l, 0);
		}
	}
	ztef(q2, mid + 1, r);
}

inline void solve1()
{
	vector<ZTEF> q;
	for (int i = 1; i <= n; i++)
	{
		q.push_back(ZTEF{i, 0, dep[i], 0, 0});
	}
	int m;
	cin >> m;
	for (int i = 1; i <= m; i++)
	{
		int l, r, k;
		cin >> l >> r >> k;
		q.push_back(ZTEF{l, r, k, i, 1});
	}
	ztef(q, 1, n);
	for (int i = 1; i <= m; i++)
	{
		cout << out1[i] << '\n';
	}
	return;
}

int main()
{
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	lg[0] = -1;
	for (int i = 1; i < n; i++)
	{
		int u, v;
		cin >> u >> v;
		es[i] = {u, v};
		e[u].push_back(v);
		e[v].push_back(u);
		dg[u]++;
		dg[v]++;
	}
	dfs1(1, 1);
	bool e = dg[1] == 1;
	for (int i = 2; i <= n; i++)
	{
		e &= dg[i] <= 2;
	}
	if (e)
	{
		solve1();
		return 0;
	}
	for (int i = 1; i < n; i++)
	{
		es[i].w = min(dep[es[i].u], dep[es[i].v]);
		// cout << es[i].u << ' ' << es[i].v << ' ' << es[i].w << endl;
	}
	sort(es + 1, es + n, cmp);
	for (int i = 1; i <= n; i++)
	{
		ff[i] = i;
		st[0][i][0] = st[1][i][0] = dfn[i];
		lg[i] = lg[i >> 1] + 1;
	}
	for (int k = 1; k <= lg[n]; k++)
	{
		for (int i = 1; i + (1 << k) <= n + 1; i++)
		{
			st[0][i][k] = min(st[0][i][k - 1], st[0][i + (1 << (k - 1))][k - 1]);
			st[1][i][k] = max(st[1][i][k - 1], st[1][i + (1 << (k - 1))][k - 1]);
		}
	}
	// cnt = n;
	// cout << cnt << endl;
	for (int i = 1; i < n; i++)
	{
		int u = find(es[i].u), v = find(es[i].v);
		cnt++;
		ff[cnt] = cnt;
		dep[cnt] = es[i].w;
		ff[u] = cnt;
		ff[v] = cnt;
		fa[u][0] = fa[v][0] = cnt;
		// cout << es[i].w << ' ' << cnt << ' ' << u << ' ' << v << endl;
	}
	fa[cnt][0] = cnt;
	for (int i = cnt; i; i--)
	{
		kdp[i] = kdp[fa[i][0]] + 1;
		for (int k = 1; k < MAXL; k++)
		{
			fa[i][k] = fa[fa[i][k - 1]][k - 1];
		}
	}
	cin >> q;
	while (q--)
	{
		int l, r, k;
		cin >> l >> r >> k;
		int res = 0;
		for (int nl = l; nl + k - 1 <= r; nl++)
		{
			int u = rnk[qstl(nl, nl + k - 1)], v = rnk[qstu(nl, nl + k - 1)];
			// cout << nl << ' ' << u << ' ' << v << ' ' << klca(u, v) << ' ' << dep[klca(u, v)] << endl;
			res = max(res, dep[klca(u, v)]);
		}
		cout << res << '\n';
	}
	return 0;
}

