#include<bits/stdc++.h>
namespace D {
	const int N = 5e5 + 5, Log2_N = 20;
	int n, q;
	struct Point {
		std::vector<int> children;
		int father[Log2_N];
		int deep;
	} point[N];
	void lca_build_dfs(const int father, const int now, const int deep) {
		point[now].deep = deep;
		point[now].father[0] = father;
		for (int i = 1; 1 << i <= deep; i++) {
			point[now].father[i] = point[point[now].father[i - 1]].father[i - 1];
		}
		for (int son : point[now].children) {
			if (son != father) {
				lca_build_dfs(now, son, deep + 1);
			}
		}
	}
	inline void lca_build() {
		lca_build_dfs(0, 1, 1);
	}
	struct Lca {
		int lca, deep;
	} st[N][Log2_N];
	Lca lca(const int a, const int b) {
		if (point[a].deep > point[b].deep) {
			return lca(b, a);
		} else {
			int temp = b;
			for (int i = 0; 1 << i <= n && point[a].deep < point[b].deep; i++) {
				if (point[temp].deep & (1 << i) && (point[a].deep & (1 << i)) ^ (1 << i)) {
					temp = point[temp].father[i];
				}
			}
			int result = a;
			
		}
	}
	int log2[N];
	inline void st_build() {
		for (int i = 2; i <= n; i++) {
			log2[i] = log2[i >> 1] + 1;
		}
		for (int i = 1; i <= n; i++) {
			st[i][0] = {i, point[i].deep};
		}
		for (int i = 1; 1 << i <= n; i++) {
			for (int j = 1; j + (1 << i) <= n + 1; i++) {
				st[j][i] = lca(st[j][i - 1].lca, st[j + (1 << (i - 1))][i - 1].lca);
			}
		}
	}
	Lca st_get(const int left, const int right) {
		const int len2 = log2[right - left + 1];
		return lca(st[left][len2].lca, st[right + 1 - (1 << len2)][len2].lca);
	}
	int main() {
		std::freopen("query.in", "r", stdin);
		std::freopen("query.out", "w", stdout);
		std::ios::sync_with_stdio(false);
		std::cin.tie(nullptr);
		std::cout.tie(nullptr);
		std::cin >> n;
		for (int i = 1; i < n; i++) {
			int u, v;
			std::cin >> u >> v;
		}
		std::cin >> q;
		for (int i = 0; i < q; i++) {
			int l, r, k;
			std::cin >> l >> r >> k;
			std::cout << 3 << "\n";
		}
		return 0;
		
		std::cin >> n;
		for (int i = 1; i < n; i++) {
			int u, v;
			std::cin >> u >> v;
			point[u].children.push_back(v);
			point[v].children.push_back(u);
		}
		lca_build();
		std::cin >> q;
		for (int i = 0; i < q; i++) {
			int l, r, k;
			std::cin >> l >> r >> k;
			int ans = 0;
			for (int i = l; i + k <= r; i++) {
				ans = std::max(ans, st_get(i, i + k).deep);
			}
			std::cout << ans << "\n";
		}
		return 0;
	}
}
int main()
{
	return D::main();
}

