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

#define ll long long
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define mkp make_pair
#define pii pair<int,int>
#define debug(x) cout << #x << " = " << x << "\n";

bool MemoryST;

const int N = 5e5 + 10;
const int inf = 1e9 + 1;

int lg[N];

struct ST {
	int a[N], f[N][22];
	int Min(int x, int y) {
		return (a[x] > a[y]) ? y : x;
	}
	void init(int n) {
//		for (int i = 1; i <= n; ++i)
//			f[i][0] = i;
		for (int k = 1; k <= 20; ++k)
			for (int i = 1; i <= n - (1 << k) + 1; ++i)
				f[i][k] = Min(f[i][k - 1], f[i + (1 << (k - 1))][k - 1]); 
	}
	int query (int l, int r) {
		int k = lg[r - l + 1];
		return Min(f[l][k], f[r - (1 << k) + 1][k]);
	}
} st;

struct node {
	int x, ls, rs, sum;
	node (int xx = 0, int lss = 0, int rss = 0, int summ = 0) {
		x = xx; ls = lss; rs = rss; sum = summ;
	}
};

struct tree {
	int ls, rs; node x; 
	tree() {
		x = node(0, 0, 0, 0); ls = rs = 0;
	}
} t[N << 5];
int tot, rt[N];

int n, q;

vi e[N]; 
int f[N][22];
int ans, tim, dep[N], dfn[N], po[N];

node CL (int l, int r) {
	return node(0, 0, 0, r - l + 1); 
}

node operator + (const node x, const node y) {
	node z; z.sum = x.sum + y.sum;
	z.x = max(x.x, y.x);
	z.x = max(z.x, x.rs + y.ls);
	z.ls = x.ls;
	if (x.sum == z.ls) z.ls += y.ls;
	z.rs = y.rs;
	if (y.sum == z.rs) z.rs += x.rs;
	return z;
}

void update (int &x, int y, int l, int r, int k) {
	x = ++tot, t[x] = t[y];
	if (l == r) {
		t[x].x = node(1, 1, 1, 1); return ;
	}
	int mid = (l + r) >> 1;
	if (k <= mid) update(t[x].ls, t[y].ls, l, mid, k);
	else update(t[x].rs, t[y].rs, mid + 1, r, k);
	t[x].x = node(0, 0, 0, 0);
	if (t[x].ls) t[x].x = t[x].x + t[t[x].ls].x;
	else t[x].x = t[x].x + CL(l, mid);
	if (t[x].rs) t[x].x = t[x].x + t[t[x].rs].x;
	else t[x].x = t[x].x + CL(mid + 1, r);
//	t[x].x = t[t[x].ls].x + t[t[x].rs].x;
//	cout << k << " " << l << " " << r << " " << t[x].x.ls << " " << t[x].x.rs << " " << t[x].x.sum << "\n";
}

node query (int x, int l, int r, int L, int R) {
	if (!x) return CL(l, r);
	if (L <= l && r <= R) return t[x].x;
	int mid = (l + r) >> 1; node p = node(0, 0, 0);
	if (L <= mid) p = p + query(t[x].ls, l, mid, L, R);
	if (R > mid) p = p + query(t[x].rs, mid + 1, r, L, R);
//	cout << l << " " << r << " " << L << " " << R << " " << p.x << "\n";
	return p;
}

int LCA (int x, int y) {
	if (x == y) return x;
	if ((x = dfn[x]) > (y = dfn[y])) swap(x, y);
	return st.query(x + 1, y);
}

void dfs1 (int u, int fa) {
	dep[u] = dep[fa] + 1;
	dfn[u] = ++tim; st.a[u] = dep[u]; st.f[tim][0] = fa; 
	for (auto v : e[u]) {
		if (v == fa) continue; 
		dfs1(v, u);
	}
}

int get (int l, int r) {
	int k = lg[r - l + 1];
	int x = LCA(f[l][k], f[r - (1 << k) + 1][k]);
	return dep[x];
}

void Mainsolve() {
	cin >> n; 
	for (int i = 1; i < n; ++i) {
		int u, v; cin >> u >> v;
		e[u].pb(v); e[v].pb(u); 
	}
	for (int i = 1; i <= n; ++i)
		lg[i] = log2(i);
	dfs1(1, 0);
	for (int i = 1; i <= n; ++i)
		po[dep[i]] = i;
	for (int i = n; i >= 1; --i) {
		rt[i] = rt[i + 1];
		if (po[i]) update(rt[i], rt[i + 1], 1, n, po[i]);
	}
	st.init(n);
	for (int i = 1; i <= n; ++i)
		f[i][0] = i;
	for (int k = 1; k <= 20; ++k)
		for (int i = 1; i <= n - (1 << k) + 1; ++i)
			f[i][k] = LCA(f[i][k - 1], f[i + (1 << (k - 1))][k - 1]); 
	cin >> q;
	while (q--) {
		int l, r, k; cin >> l >> r >> k;
//		cout << k << " " << r - l + 1 << "\n";
		if ((n <= 5000 && q <= 5000) || (k == r - l + 1)) {
			ans = 0;
			for (int i = l; i <= r - k + 1; ++i) {
				ans = max(ans, get(i, i + k - 1));
			}
//			cout << k << " " << r - l + 1 << "\n";
//			cout <<n << " " << q<< " " << l << " " << r<< " " << k << "\n";
			cout << ans << "\n";
		} else {
			int L = 1, R = n;
			while (L < R) {
				int mid = (L + R) >> 1;
				node x = query(rt[mid + 1], 1, n, l, r);
				if (x.x >= k) L = mid + 1;
				else R = mid;
			}
			cout << L << "\n";
		}
	}
}

bool MemoryED;

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	cerr << fixed << setprecision(6) << (&MemoryST - &MemoryED) / 1024.0 / 1024.0 << "MB\n";

	int T = 1; //cin >> T;
	while (T--) Mainsolve();

	cerr << 1e3 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}

