#include <bits/stdc++.h>
using namespace std;
#define lson k << 1
#define rson k << 1 | 1
const int N = 5e5+100;

struct R {
	int u, v, lst;
}road[N<<1];

struct T {
	int k, l, r, minn = 0x3f3f3f3f, maxn = 0;
}tr[N<<2];

int n, fa[N][31], final[N], id, q, dep[N], lg[N], child[N];

void pushup (int k) {
	tr[k].minn = min(tr[lson].minn, tr[rson].minn);
	tr[k].maxn = max(tr[lson].maxn, tr[rson].maxn);
}

void build (int k, int l, int r) {
	tr[k].l = l, tr[k].r = r;
	if (l == r) {
		tr[k].minn = dep[l];
		tr[k].maxn = dep[l];
		return;
	}
	
	int mid = (l+r) >> 1;
	build(lson, l, mid);
	build(rson, mid+1, r);
	pushup(k);
}

void add (int tu, int tv) {
	road[++id].u = tu;
	road[id].v = tv;
	road[id].lst = final[tu];
	final[tu] = id;
}

void dfs (int now, int fat) {
	fa[now][0] = fat;
	dep[now] = dep[fat]+1;
	for (int i = 1;i <= 31;i++) fa[now][i] = fa[fa[now][i-1]][i-1];
	for (int i = final[now];i;i = road[i].lst) {
		int to = road[i].v;
		if (to == fat) continue;
		dfs(to, now);
	}
}

int LCA (int a, int b) {
	if (dep[a] < dep[b]) swap(a, b);
	while (dep[a] > dep[b]) a = fa[a][lg[dep[a]-dep[b]]-1];
	if (a == b) return b;
	for (int i = 0;i <= lg[dep[a]]-1;i++) if (fa[a][i] != fa[b][i]) a = fa[a][i], b = fa[b][i];
	return fa[a][0];
}

void dfs1 (int now, int root) {
	dep[now] = dep[root]+1;
	for (int i = final[now];i;i = road[i].lst) {
		int to = road[i].v;
		if (to != root) dfs1(to, now);
		else continue;
	}
}

int query1 (int k, int l, int r) {
	if (tr[k].l >= l && tr[k].r <= r) return tr[k].maxn;
	int mid = (tr[k].l+tr[k].r) >> 1;
//	cout << mid << endl;
	int res = 0;
	if (mid >= l) res = max(res, query1(lson, l, r));
	if (mid < r) res = max(res, query1(rson, l, r));
//	cout << res << endl;
	return res;
}

int query_min (int k, int l, int r) {
	if (tr[k].l >= l && tr[k].r <= r) return tr[k].minn;
	int mid = (tr[k].l+tr[k].r) >> 1;
	int res = 0x3f3f3f3f;
	if (mid >= l) res = min(res, query_min(lson, l, r));
	if (mid < r) res = min(res, query_min(rson, l, r));
	return res;
}

int main () {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	scanf("%d", &n);
	for (int i = 1;i <= n;i++) lg[i] = lg[i-1] + (1 << lg[i-1] == i);
	for (int i = 1;i < n;i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		add(u, v);
		add(v, u);
		child[u]++;
		child[v]++;
	}
	
	bool check = false;
	for (int i = 1;i <= n;i++) if (child[i] > 2) check = true;
	if (!check) {
		dfs1(1, 0); // ÌØÊâÐÔÖÊA 
		build(1, 1, n);
		scanf("%d", &q);
		for (int i = 1;i <= q;i++) {
			int l, r, k;
			scanf("%d%d%d", &l, &r, &k);
			if (k == 1) printf("%d\n", query1(1, l, r));
			else {
				int ans = 0;
				for (int j = 1;j <= n-k+1;j++) ans = max(ans, query_min(1, j, j+k-1));
				printf("%d\n", ans);
			}
		}
	}else {
		dfs(1, 0);
		scanf("%d", &q);
		for (int i = 1;i <= q;i++) {
			int l, r, k;
			scanf("%d%d%d", &l, &r, &k);
			int ans = 0;
			for (int j = k+1;j <= (r-l)+1;j++) {
				for (int p = 1;p <= n-j+1;p++) {
					for (int z = p+1;z <= p+j-1;z++) {
						int faa = LCA(z, z-1);
						ans = max(ans, dep[faa]);
					}
				}
			}
			printf("%d\n", ans);
		}
	}
	return 0;
}
