#include<bits/stdc++.h>

using namespace std;

const int maxn = 5e5 + 10;
const int B = 22;

int n;

vector<int> G[maxn];

int deep[maxn];
int lca[maxn][B];

int q;

void dfs(int u, int fa) {
	for (int k = 0; ~lca[u][k]; k++) {
		lca[u][k+1] = lca[lca[u][k]][k];
	}
	
	for (int v: G[u]) if (v != fa) {
		deep[v] = deep[u] + 1;
		lca[v][0] = u;
		dfs(v, u);
	}
}

int query_lca(int u, int v) {
	if (u == v) return u;
	if (deep[u] < deep[v]) swap(u, v); // keep deep[u] > deep[v]
	for (int k = B-1; k >= 0; k--) {
		if (~lca[u][k] && deep[lca[u][k]] >= deep[v]) u = lca[u][k];
	}
	if (u == v) return u;
	for (int k = B-1; k >= 0; k--) {
		if (lca[u][k] != lca[v][k]) {
			u = lca[u][k];
			v = lca[v][k];
		}
	}
	return lca[u][0];
}

int st[maxn][B];
int lg2[maxn];

int query_st(int l, int r) {
	int k = lg2[r - l + 1];
	return query_lca(st[l][k], st[r - (1 << k) + 1][k]);
}


void init() {
	lg2[1] = 0;
	for (int i = 2; i <= n; i++) lg2[i] = lg2[i >> 1] + 1;
	deep[1] = 1;
	memset(lca, -1, sizeof(lca));
	dfs(1, -1);
	for (int k = 0, len = 1; len <= n; k++, len *= 2) {
		for (int l = 1, r = len; r <= n; l++, r++) {
			if (k == 0) st[l][k] = l;
			else st[l][k] = query_lca(st[l][k-1], st[l+len/2][k-1]);
		}
	}
}

int cal(int l, int r, int len) {
	int ans = 1;
	for (int lt = l, rt = l + len - 1; rt <= r; lt++, rt++) {
		ans = max(ans, deep[query_st(lt, rt)]);
	}
	return ans;
}

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	
	cin >> n;
	for (int i = 1; i <= n-1; i++) {
		int u, v;
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	
	init();
	
	
	cin >> q;
	for (int i = 1; i <= q; i++) {
		int l, r, k;
		cin >> l >> r >> k;
		cout << cal(l, r, k) << endl;
	}
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}


