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

const int N = 5e6 + 7;
vector<int> g[N];

int depth[N], fa[N];

struct Seg{
	int l, r;
	int max;
};

Seg tr[N * 4];

void pushup(int rt) {
	tr[rt].max = max(tr[rt * 2].max, tr[rt * 2 + 1].max);
}

void build(int rt, int l, int r) {
	tr[rt].l = l, tr[rt].r = r;
	if (l == r) {
		tr[rt].max = depth[l];
		return;
	}
	int mid = (l + r) / 2;
	build(rt * 2, l, mid);
	build(rt * 2 + 1, mid + 1, r);
	pushup(rt);
}

int query(int rt, int l, int r) {
	if (l <= tr[rt].l && tr[rt].r <= r) {
		return tr[rt].max;
	}
	int ans = 0;
	int mid = (tr[rt].l + tr[rt].r) / 2;
	if (l <= mid) ans = max(ans, query(rt * 2, l, r));
	if (r > mid) ans = max(ans, query(rt * 2 + 1, l, r));
	return ans;
}

void dfs(int u, int pre) {
	depth[u] = depth[pre] + 1;
	for (int v : g[u]) {
	//	fa[v] = u;
		if (v != pre) dfs(v, u);
	}
}

void sub() {
	int q;
	cin >> q;
	while (q--) {
		int l, r, k;
		cin >> l >> r >> k;
		cout << query(1, l, r) << '\n';
	}
}

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	ios::sync_with_stdio(false);
	int n, q;
	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);
	build(1, 1, n);

	// for (int i = 1; i <= n; i++) {
	// 	cout << depth[i] << ' ';
	// }
	// cout << '\n';

	if (tr[1].max == n) {
		sub();
		return 0;
	}

	cin >> q;
	while (q--) {
		int l, r, k;
		cin >> l >> r >> k;
		cout << query(1, l, r) << '\n';
	}

	return 0;
}