#include <iostream>
#include <cstring>
#include <cctype>
#include <cstdio>
using namespace std;
namespace IO {
	inline int Read() {
		int x = 0, k = 0; char ch = getchar();
		while (!isdigit(ch)) k |= (ch == '-'), ch = getchar();
		while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
		return k ? -x : x;
	}
}
const int MaxN = 5E5 + 10;
int c, m, n, T, tot;
int dep[MaxN], head[MaxN];
int f[MaxN][20];
struct Edge{ int v, nxt; } e[2 * MaxN];
inline void AddEdge(int u, int v) {
	e[++tot].nxt = head[u], head[u] = tot;
	e[tot].v = v;
}
void DFS(int u, int fa) {
	f[u][0] = fa, dep[u] = dep[fa] + 1;
	for (register int k = 1; k <= 19; k++) f[u][k] = f[f[u][k - 1]][k - 1];
	for (register int i = head[u]; i; i = e[i].nxt) {
		int v = e[i].v;
		if (v == fa) continue;
		DFS(v, u);
	}
}
int LCA(int u, int v) {
	if (dep[u] > dep[v]) swap(u, v);
	for (register int i = 19; i >= 0; i--) {
		if (dep[f[v][i]] >= dep[u]) v = f[v][i];
	}
	if (u == v) return u;
	for (register int k = 19; k >= 0; k--) {
		if (dep[f[u][k]] != dep[f[v][k]]) {
			u = f[u][k], v = f[v][k];
		}
	}
	return f[u][0];
}
int Calc(int l, int r) {
	if (l == r) return l;
	if (l == r - 1) return LCA(l, r);
	int mid = (l + r) >> 1;
	int ret = Calc(l, mid);
	if (mid + 1 <= r) ret = LCA(ret, Calc(mid + 1, r));
	return ret;
}
int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	n = IO::Read();
	for (register int i = 1; i < n; i++) {
		int u = IO::Read(), v = IO::Read();
		AddEdge(u, v);
		AddEdge(v, u);
	}
	DFS(1, 0);
	m = IO::Read();
	for (register int i = 1; i <= m; i++) {
		int l = IO::Read(),r = IO::Read(), k = IO::Read(), ans = 0;
		for (register int len = k; len <= r - l + 1; len++) {
			for (register int i = l; i + len - 1 <= r; i++) {
				int j = i + len - 1, lca = i;
				lca = Calc(i, j);
				ans = max(ans, dep[lca]);
			}
		}
		cout << ans << endl;
	}
	return 0;
}
/*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3
*/
