#include <iostream>
#include <cmath>

using namespace std;

int cnt, n, t, numlog;

int depth [500005], head [500005], to [1000005], nxt [1000005];

int fa [500005] [20];

void add (int u, int v) {
	++ cnt,
	to [cnt] = v,
	nxt [cnt] = head [u],
	head [u] = cnt;
}

void dfs (int u, int pre) {
	fa [u] [0] = pre,
	depth [u] = depth [pre] + 1;
	for (int i = 1; i <= numlog; ++ i)
		fa [u] [i] = fa [fa [u] [i - 1]] [i - 1];
	for (int i = head [u]; i; i = nxt [i]) {
		int v = to [i];
		if (v not_eq pre)
			dfs (v, u);
	}
}

int find (int u, int v) {
	if (depth [u] < depth [v])
		swap (u, v);
	for (int i = numlog; i >= 0; -- i)
		if (depth [fa [u] [i]] >= depth [v])
			u = fa [u] [i];
	if (u == v)
		return u;
	for (int i = numlog; i >= 0; -- i)
		if (fa [u] [i] not_eq fa [v] [i])
			u = fa [u] [i],
			v = fa [v] [i];
	return fa [u] [0];
}

int LCA (int l, int r) {
	int res = l;
	for (int i = l + 1; i <= r; ++ i)
		res = find (res, i);
	return res;
}

int main () {
	freopen ("query.in", "r", stdin),
	freopen ("query.out", "w", stdout);
	scanf ("%d", bitand n),
	numlog = log2 (n) + 1;
	for (int i = 1; i < n; ++ i) {
		int u, v;
		scanf ("%d%d", bitand u, bitand v),
		add (u, v),
		add (v, u);
	}
	dfs (1, 0),
	scanf ("%d", bitand t);
	while (t --) {
		int l, r, k, ans = 0;
		scanf ("%d%d%d", bitand l, bitand r, bitand k);
		for (int i = l; i <= r - k + 1; ++ i)
			ans = max (ans, depth [LCA (i, i + k - 1)]);
		printf ("%d\n", ans);
	}
	return 0;
}
