#include<bits/stdc++.h>
#define rep(rp,a,b) for(int rp=a;rp<=b;++rp)
#define per(pr,a,b) for(int pr=a;pr>=b;--pr)
#define Rep(rp,a,b) for(int rp=a;rp<b;++rp)
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int N = 5e3+5, MOD = 1e9+7, N2 = 5e5+5;
inline int read() {
	int x = 0, f = 1; char ch = 0;
	while (!isdigit(ch)) {ch = getchar(); if (ch == '-') f *= -1;}
	while (isdigit(ch)) x = x*10+(ch^48), ch = getchar();
	return f*x;
}

int n;
vector<int> G[N2];
int dep[N2], dfn[N2], st[N2<<1][23], cntn, st2[N2][23], deg[N2];

void dfs(int x, int par = 0) {
	dep[x] = dep[par]+1;
	st[++cntn][0] = x;
	dfn[x] = cntn;
	for (int y:G[x]) if (y != par) dfs(y, x), st[++cntn][0] = x;
}

void buildst() {
	rep (j, 1, __lg(cntn))
		rep (i, 1, cntn-(1<<j)+1) {
			if (dep[st[i][j-1]] < dep[st[i+(1<<(j-1))][j-1]]) st[i][j] = st[i][j-1];
			else st[i][j] = st[i+(1<<(j-1))][j-1];
		}
}

int lca(int x, int y) {
	if (x == y) return x;
	x = dfn[x], y = dfn[y];
	if (x > y) swap(x, y);
	int lgg = __lg(y-x+1);
	if (dep[st[x][lgg]] < dep[st[y-(1<<lgg)+1][lgg]]) return st[x][lgg];
	else return st[y-(1<<lgg)+1][lgg];
}

void buildst2() {
	rep (i, 1, n) st2[i][0] = i;
	rep (j, 1, __lg(n))
		rep (i, 1, n-(1<<j)+1) {
			st2[i][j] = lca(st2[i][j-1], st2[i+(1<<(j-1))][j-1]);
		}
}

int lrlca(int L, int R) {
	int lgg = __lg(R-L+1);
	return lca(st2[L][lgg], st2[R-(1<<lgg)+1][lgg]);
}

void solve() {
	n = read();
	rep (i, 1, n-1) {
		int u = read(), v = read();
		G[u].eb(v), G[v].eb(u);
		++deg[u], ++deg[v];
	}
	// bool flg = 0;
	// rep (i, 1, n) {
	// 	if (deg[i] == 1) ++cnt;
	// 	if (deg[i] > 2) flg = 1;
	// }
	dfs(1);
	buildst();
	buildst2();
	int Q = read();
	while (Q --) {
		int L = read(), R = read(), k = read(), ans = 1;
		rep (i, L, R-k+1) ans = max(ans, dep[lrlca(i, i+k-1)]);
		printf("%d\n", ans);
	}
}

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	int T = 1; while (T --) solve();
	return 0;
}
