// Code by Heratino & Nelofus
// No I still can't seem to
// Sing more than blues when It's time for my verse
// It's true that I need you
// To turn my blues into bursting fireworks
#include <bits/stdc++.h>
using i64 = long long;

template<typename T>
inline void chkmax(T &a, const T &b) {if (a < b)	a = b;}

bool start;
constexpr int N = 5e5 + 10;
int n;
std::vector<int> G[N];
namespace Case_Chain {
	struct info {
		int f, s;
		int lmax, rmax, mx;
	};
	struct node {
		int ls, rs;
		info a;
		// s zai f = 0 de shi hou shi cuo de
		// dan shi zhe ge shi hou s yong bu dao
	} tr[N * 22];

	inline info operator + (const info &ls, const info &rs) {
		info r;
		if (ls.f)
			r.lmax = ls.s + rs.lmax;
		else
			r.lmax = ls.lmax;
		if (rs.f)
			r.rmax = ls.rmax + rs.s;
		else
			r.rmax = rs.rmax;
		r.s = ls.s + rs.s;
		r.f = ls.f | rs.f;
		r.mx = std::max({ls.mx, rs.mx, ls.rmax + rs.lmax});
		return r;
	}

	inline void pull(int u) {
		auto &ls = tr[tr[u].ls], &rs = tr[tr[u].rs];
		auto &r = tr[u];
		r.a = ls.a + rs.a;
	}

	int tot;
	int dep[N];
	int nd[N], rt[N];
	void dfs(int u, int fa) {
		dep[u] = dep[fa] + 1;
		nd[dep[u]] = u;
		for (const int &v : G[u]) {
			if (v == fa)
				continue;
			dfs(v, u);
		}
	}
	void modify(int &u, int v, int l, int r, int p) {
		u = ++tot;
		tr[u] = tr[v];
		if (l == r) {
			tr[u].a.f = 1;
			tr[u].a.lmax = tr[u].a.rmax = 1;
			tr[u].a.mx = 1;
			tr[u].a.s = 1;
			return ;
		}
		int mid = (l + r) / 2;
		if (p <= mid)
			modify(tr[u].ls, tr[v].ls, l, mid, p);
		if (p > mid)
			modify(tr[u].rs, tr[v].rs, mid + 1, r, p);
		pull(u);
	}
	info query(int u, int l, int r, int ql, int qr) {
		if (ql == l && r == qr) {
			return tr[u].a;
		}
		int mid = (l + r) / 2;
		if (qr <= mid)
			return query(tr[u].ls, l, mid, ql, qr);
		if (ql > mid)
			return query(tr[u].rs, mid + 1, r, ql, qr);
		return query(tr[u].ls, l, mid, ql, mid) + query(tr[u].rs, mid + 1, r, mid + 1, qr);
	}
	void pre() {
		for (int i = n; i >= 1; i--) {
			rt[i] = rt[i + 1];
			modify(rt[i], rt[i], 1, n, nd[i]);
		}
	}
	int qry(int l, int r, int k) {
		int ll = 1, rr = n + 1;
		while (ll < rr) {
			int mid = (ll + rr) / 2;
			if (query(rt[mid], 1, n, l, r).mx >= k)
				ll = mid + 1;
			else
				rr = mid;
		}
		return ll - 1;
	}
}

int fa[N], dep[N];
int dfn[N], dfc;
int rk[N];
void dfs(int u) {
	dep[u] = dep[fa[u]] + 1;
	dfn[u] = ++dfc;
	rk[dfc] = u;
	for (const int &v : G[u]) {
		if (v == fa[u])
			continue;
		fa[v] = u;
		dfs(v);
	}
}

int st1[20][N];
int st2[20][N];

inline int LCA(int u, int v) {
	if (u == v)
		return u;
	int l = dfn[u], r = dfn[v];
	if (l > r)	std::swap(l, r);
	l++;
	int k = std::__lg(r - l + 1);
	if (dfn[fa[st1[k][l]]] < dfn[fa[st1[k][r - (1 << k) + 1]]])
		return fa[st1[k][l]];
	else
		return fa[st1[k][r - (1 << k) + 1]];
}
inline int qry(int l, int r) {
	int k = std::__lg(r - l + 1);
	return LCA(st2[k][l], st2[k][r - (1 << k) + 1]);
}
bool end;

int main() {
#ifdef Insight
	std::cerr << ((&end) - (&start)) / 1048576.0 << '\n';
#endif
#ifdef HeratinoNelofus
	freopen("input.txt", "r", stdin);
#else
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
#endif
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	std::cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v;
		std::cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	bool chain = true;
	for (int i = 1; i <= n; i++) {
		if (G[i].size() > 2)
			chain = false;
	}
	if (chain && G[1].size() == 1) {
		Case_Chain::dfs(1, 0);
		Case_Chain::pre();
		int q;
		std::cin >> q;
		for (int _ = 1; _ <= q; _++) {
			int l, r, k;
			std::cin >> l >> r >> k;
			std::cout << Case_Chain::qry(l, r, k) << '\n';
		}
	} else {
		dfs(1);
		for (int i = 1; i <= n; i++)
			st1[0][i] = rk[i], st2[0][i] = i;
		for (int k = 1; k < 20; k++) {
			for (int i = 1; i + (1 << k) - 1 <= n; i++) {
				if (dfn[fa[st1[k - 1][i]]] < dfn[fa[st1[k - 1][i + (1 << (k - 1))]]]) {
					st1[k][i] = st1[k - 1][i];
				} else {
					st1[k][i] = st1[k - 1][i + (1 << (k - 1))];
				}
			}
		}
		for (int k = 1; k < 20; k++)
			for (int i = 1; i + (1 << k) - 1 <= n; i++)
				st2[k][i] = LCA(st2[k - 1][i], st2[k - 1][i + (1 << (k - 1))]);
		int q;
		std::cin >> q;
		for (int _ = 1; _ <= q; _++) {
			int l, r, k;
			std::cin >> l >> r >> k;
			int ans = 0;
			for (int i = l + k - 1; i <= r; i++) {
				int t = qry(i - k + 1, i);
				chkmax(ans, dep[t]);
			}
			std::cout << ans << '\n';
		}
	}
	return 0;
}
