#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

ll getInt() {
	ll s = 0, f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-') f = -1;
	for (; isdigit(c); c = getchar())
		s = s * 10 + c - '0';
	return s * f;
}

const int N = 5e5 + 10;

struct Graph {
	struct Edge {
		ll to;
		Edge *nxt;
	} edge[2 * N];
	Edge *hd[N];

	void add(ll u, ll v) {
		static int cnt = 0;
		hd[u] = &(edge[++cnt] = {v, hd[u]});
	}

	ll p[N][30];
	ll dep[N];

	void dfs(ll x, ll fa) {
		dep[x] = dep[fa] + 1;
		p[x][0] = fa;

		for (auto e = hd[x]; e != nullptr; e = e->nxt) {
			ll v = e->to;
			if (v == fa) continue;
			dfs(v, x);
		}
	}

	void init(ll n) {
		for (int k = 1; k <= 20; ++k) {
			for (int i = 1; i <= n; ++i) {
				p[i][k] = p[p[i][k - 1]][k - 1];
			}
		}
	}

	ll lca(ll x, ll y) {
		if (dep[x] < dep[y]) swap(x, y);
		for (int i = 20; i >= 0; --i) {
			if (dep[p[x][i]] >= dep[y]) {
				x = p[x][i];
			}
		}
		if (x == y) return x;

		for (int i = 20; i >= 0; --i) {
			if (p[x][i] != p[y][i]) {
				x = p[x][i];
				y = p[y][i];
			}
		}

		return p[x][0];
	}

} gph;


ll getAns(ll l, ll r, ll k) {
	ll ans = INT_MIN;

	for (int i = l; i <= r - k + 1; ++i) {
		ll c = i;
		for (int j = i + 1; j <= i + k - 1; ++j) {
			c = gph.lca(c, j);
		}
		ans = max(ans, gph.dep[c]);
	}
	return ans;
}


int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	ll n = getInt();
	for (int i = 1; i <= n - 1; ++i) {
		ll u = getInt(), v = getInt();
		gph.add(u, v);
		gph.add(v, u);
	}

	gph.dfs(1, 0);
	gph.init(n);

	ll q = getInt();

	for (int i = 1; i <= q; ++i) {
		ll l = getInt(), r = getInt(), k = getInt();
		printf("%lld\n", getAns(l, r, k));
	}




	fclose(stdin);
	fclose(stdout);
	return 0;
}
