#include <bits/stdc++.h>
#define USE_FREOPEN
//#define MUL_TEST
#define FILENAME "query"

const int N = 5e5 + 5;
int n, q, head[N], tot;
int f[N][25];
struct Edge {
	int to, next;
} e[N << 1];
int real_lca[5005][5005], dep[N];
int max_dep;
bool AAAA;

int st[N][20];

void add(int u, int v) {
	e[tot] = (Edge){v, head[u]};
	head[u] = tot;
	++tot;
}

void read(int &x) {
	x = 0;
	int w = 1, c = getchar();
	while (c < '0' || '9' < c) {
		if (c == '-') w = -1;
		c = getchar();
	}
	while ('0' <= c && c <= '9') {
		x = x * 10 + (c - '0');
		c = getchar();
	}
	x *= w;
}

void dfs(int u, int fa) {
	f[u][0] = fa;
	dep[u] = dep[fa] + 1;
	max_dep = std::max(max_dep, dep[u]);
	for (int i = 1; i <= 16; ++i)
		f[u][i] = f[f[u][i - 1]][i - 1];
	for (int i = head[u]; ~i; i = e[i].next) {
		int v = e[i].to;
		if (v == fa) continue;
		dfs(v, u);
	}
}

int lca(int u, int v) {
	if (u == v) return u;
	if (dep[u] < dep[v]) std::swap(u, v);
	for (int i = 16; ~i; --i) {
		if (dep[f[u][i]] >= dep[v]) u = f[u][i];
		if (u == v) return u;
	}
	for (int i = 16; ~i; --i) {
		if (f[u][i] != f[v][i]) u = f[u][i], v = f[v][i];
	}
	return f[u][0];
}

int st_find(int l, int r) {
	int len = r - l + 1, Log = log2(len);
	return std::min(st[l][Log], st[r - (1 << Log) + 1][Log]);
}

void solve() {
	memset(head, -1, sizeof head);
	read(n);
	for (int i = 1, u, v; i < n; ++i) {
		read(u); read(v);
		add(u, v); add(v, u);
	}
	dfs(1, 1);
	if (max_dep == n) AAAA = 1;
	if (n <= 5000) {
		for (int i = 1; i <= n; ++i) {
			real_lca[i][i] = i;
			for (int j = i + 1; j <= n; ++j) {
				real_lca[i][j] = lca(real_lca[i][j - 1], j);
//				printf("lca dep %d, %d is %d\n", i, j, real_lca[i][j]);
			}
		}
	}
	for (int i = 1; i <= n; ++i) st[i][0] = dep[i];
	for (int i = 1; i <= 15; ++i) {
		for (int j = 1; j <= n; ++j) {
			st[j][i] = std::min(st[j][i - 1], st[j + (1 << (i - 1))][i - 1]);
		}
	}
	read(q);
	int l, r, k;
	for (int i = 1; i <= q; ++i) {
		read(l); read(r); read(k);
		if (n <= 5000) {
			int ans = 0;
			for (int x = l, y = l + k - 1; y <= r; ++x, ++y) {
				ans = std::max(ans, dep[real_lca[x][y]]);
			}
			printf("%d\n", ans);
		}
		else if (AAAA){
			int ans = 0;
			for (int x = l, y = l + k - 1; y <= r; ++x, ++y) {
				ans = std::max(ans, st_find(x, y));
			}
			printf("%d\n", ans);
		}
	}
}

signed main() {
#ifdef USE_FREOPEN
	freopen(FILENAME ".in", "r", stdin);
	freopen(FILENAME ".out", "w", stdout);
#endif

	int _ = 1;
#ifdef MUL_TEST
	scanf("%d", &_);
#endif
	while (_--) solve();
	_ ^= _;
	return (0^_^0);
}


