#include<bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5, inf = 0x3f3f3f3f;
#define ll long long
int inline read() {
	int num = 0, f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9') { num = (num << 3) + (num << 1) + (ch ^ 48); ch = getchar(); }
	return num * f;
}
int n, q, tot, a[N]; 
int dep[N], L[N], R[N]; 
vector<int> e[N]; 
void dfs(int u, int fa) {
	dep[u] = dep[fa] + 1, a[++tot] = dep[u]; 
	L[u] = tot, R[u] = -tot; 
	for(int v : e[u]) if(v != fa) {
		dfs(v, u), a[++tot] = dep[u], R[u] = -tot; 
	}
}
struct SpraseTable {
	int n, st[20][N]; 
	SpraseTable(int *a, int n) : n(n) { build(a); }
	void build(int *a) {
		int t = __lg(n); 
		for(int i = 1; i <= n; ++i) st[0][i] = a[i];
		for(int j = 1; j <= t; ++j) {
			for(int i = 1; i + (1 << j) - 1 <= n; ++i) {
				int u = st[j - 1][i], v = st[j - 1][i + (1 << j - 1)]; 
				st[j][i] = min(u, v); 
			}
		}
	}
	inline int ask(int l, int r) { 
		int t = __lg(r - l + 1); 
		return min(st[t][l], st[t][r - (1 << t) + 1]); 
	}
}; 
int main() {
#define file
#ifdef file
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
#endif
	n = read(); 
	for(int i = 1; i < n; ++i) {
		int u = read(), v = read(); 
		e[u].emplace_back(v);
		e[v].emplace_back(u); 
	}
	dfs(1, 0); 
	q = read(); 
	SpraseTable tp(a, tot), tl(L, n), tr(R, n); 
	while(q--) {
		int l = read(), r = read(), k = read(), ans = 0; 
		while(l + k - 1 <= r) {
			int pl = tl.ask(l, l + k - 1); 
			int pr = -tr.ask(l, l + k - 1); 
			ans = max(ans, tp.ask(pl, pr)); 
			++l; 
		}
		printf("%d\n", ans); 
	}
	return 0;
}
/*
如何优雅的求两个节点的 lca
求出欧拉序，然后变成 RMQ 问题
显然可以拓展到多个节点
并且每次肯定只会选择最小的区间 
于是你已经会 O(\sum len - k + 1) 了 

6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3


*/
