#include <bits/stdc++.h>
using namespace std;
inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar(); }
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return x * f;
}
const int N = 5e5 + 10;
int n;
vector<int> e[N];
int dep[N], fa[N], dfn[N], siz[N], tim;
void dfs(int u, int f) {
	fa[u] = f, dep[u] = dep[f] + 1, dfn[u] = ++tim, siz[u] = 1;
	for(auto v : e[u]) {
		if(v == f) continue;
		dfs(v, u);
		siz[u] += siz[v];
	}
}
namespace st_table {
	int st[20][N], st2[20][N];
	int Min(int u, int v) { return dep[u] < dep[v] ? u : v; }
	void init() {
		for(int i = 1; i <= n; i++) st[0][dfn[i]] = i;
		for(int i = 1; (1 << i) <= n; i++)
			for(int j = 1; j + (1 << i) - 1 <= n; j++)
				st[i][j] = Min(st[i - 1][j], st[i - 1][j + (1 << i - 1)]);
	}
	int query(int l, int r) {
		int L = 31 ^ __builtin_clz(r - l + 1);
		return Min(st[L][l], st[L][r - (1 << L) + 1]);
	}
	int LCA(int u, int v) {
		if(u == v) return u;
		if(dfn[u] > dfn[v]) swap(u, v);
		return fa[query(dfn[u] + 1, dfn[v])];
	}
	void init2() {
		for(int i = 1; i <= n; i++) st2[0][i] = i;
		for(int i = 1; (1 << i) <= n; i++)
			for(int j = 1; j + (1 << i) - 1 <= n; j++)
				st2[i][j] = LCA(st2[i - 1][j], st2[i - 1][j + (1 << i - 1)]);
	}
	int query2(int l, int r) {
		int L = 31 ^ __builtin_clz(r - l + 1);
		return LCA(st2[L][l], st2[L][r - (1 << L) + 1]);
	}
} using namespace st_table;
int main() {
//	system("fc query3.ans query.out");
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	n = read();
	for(int i = 1, u, v; i < n; i++) {
		u = read(), v = read();
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(1, 0);
//	return 0;
	init();
	init2();
	int q = read();
	while(q--) {
		int l = read(), r = read(), k = read();
		int ans = 0;
		for(int i = l; i + k - 1 <= r; i++)
			ans = max(ans, dep[query2(i, i + k - 1)]);
		printf("%d\n", ans);
	}
	return 0;
}
