#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppp;
int n, q;
vector<int> e[500005];
int sz[500005], fa[500005], dep[500005];
void srh1(int x, int pr, int d)
{
	sz[x] = 1;
	fa[x] = pr;
	dep[x] = d;
	for(int i : e[x])
	{
		if(i != pr)
		{
			srh1(i, x, d + 1);
			sz[x] += sz[i];
		}
	}
	for(int i=1;i<e[x].size();i++)
	{
		if(e[x][0] == pr || (e[x][i] != pr && sz[e[x][i]] > sz[e[x][0]]))
		{
			swap(e[x][i], e[x][0]);
		}
	}
}
int tp[500005], dfn[500005], num[500005], dfn_cnt = 0;
void srh2(int x, int _tp)
{
	tp[x] = _tp;
	num[dfn[x] = ++dfn_cnt] = x;
	for(int i=0;i<e[x].size();i++)
	{
		if(e[x][i] != fa[x])
		{
			srh2(e[x][i], (i ? e[x][i] : _tp));
		}
	}
}
int lca(int x, int y)
{
	if(tp[x] == tp[y])
	{
		return dep[x] < dep[y] ? x : y;
	}
	if(dep[tp[x]] < dep[tp[y]])
	{
		swap(x, y);
	}
	return lca(fa[tp[x]], y);
}
struct SegTree {
	vector<ppp> val; // {{mx, mxp}, {mn, mnp}}
	ppp id = make_pair(make_pair(-2000000000, 0), make_pair(2000000000, 0));
	int sz;
	SegTree() {}
	ppp mrg(ppp x, ppp y)
	{
		return make_pair(x.first.first > y.first.first ? x.first : y.first, x.second.first < y.second.first ? x.second : y.second);
	}
	void pushup(int x)
	{
		val[x] = mrg(val[x * 2], val[x * 2 + 1]);
	}
	void build(int x, int lx, int rx, vector<int>& a)
	{
		if(rx - lx == 1)
		{
			if(lx <= a.size())
			{
				val[x] = make_pair(make_pair(a[lx - 1], lx), make_pair(a[lx - 1], lx));
			}
			return;
		}
		int mid = (lx + rx) / 2;
		build(x * 2, lx, mid, a);
		build(x * 2 + 1, mid, rx, a);
		pushup(x);
	}
	SegTree(vector<int>& a)
	{
		for(sz=1;sz<a.size();sz*=2);
		val = vector<ppp>(sz * 2, id);
		build(1, 1, sz + 1, a);
	}
	ppp qry(int x, int lx, int rx, int l, int r)
	{
		if(lx >= l && rx <= r)
		{
			return val[x];
		}
		if(lx >= r || rx <= l)
		{
			return id;
		}
		int mid = (lx + rx) / 2;
		return mrg(qry(x * 2, lx, mid, l, r), qry(x * 2 + 1, mid, rx, l, r));
	}
	ppp qry(int l, int r)
	{
		return qry(1, 1, sz + 1, l, r + 1);
	}
};
bool subB = 1;
struct Query {
	int l, r, k;
	void in()
	{
		cin >> l >> r >> k;
		subB &= (k == r - l + 1);
	}
} qr[500005];
int main()
{
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	cin >> n;
	for(int i=1;i<=n-1;i++)
	{
		int u, v;
		cin >> u >> v;
		e[u].push_back(v); e[v].push_back(u);
	}
	srh1(1, 0, 1);
	srh2(1, 1);
	cin >> q;
	bool subA = 0;
	for(int i=1;i<=n;i++)
	{
		subA |= (dep[i] == n);
	}
	for(int i=1;i<=q;i++)
	{
		qr[i].in();
	}
	vector<int> initarr(n);
	for(int i=1;i<=n;i++)
	{
		initarr[i - 1] = dfn[i];
	}
	SegTree st(initarr);
	if(subB)
	{
		for(int i=1;i<=q;i++)
		{
			ppp tmp = st.qry(qr[i].l, qr[i].r);
			cout << dep[lca(tmp.first.second, tmp.second.second)] << endl;
		}
		return 0;
	}
	for(int i=1;i<=q;i++)
	{
		int mx = 0;
		for(int j=qr[i].l;j+qr[i].k-1<=qr[i].r;j++)
		{
			ppp tmp = st.qry(j, j + qr[i].k - 1);
			mx = max(mx, dep[lca(tmp.first.second, tmp.second.second)]);
		}
		cout << mx << endl;
	}
	return 0;
}
