#include <bits/stdc++.h>
using namespace std;
#define MAXN 500005
#define MAXK 19

int n, q, cnt;
int dfn[MAXN], dep[MAXN], fa[MAXN][MAXK];
vector<int> e[MAXN];
void dfs(int x, int f){dfn[x]=++cnt; dep[x]=dep[fa[x][0]=f]+1; for (auto i: e[x]) if (i ^ f) dfs(i, x);}
int LCA(int x, int y){
	if (dep[x] > dep[y]) swap(x, y); for (int i(MAXK-1); ~i; --i) if (dep[fa[y][i]] >= dep[x]) y = fa[y][i];
	if (x == y) return x; for (int i(MAXK-1); ~i; --i) if (fa[x][i] ^ fa[y][i]) x = fa[x][i], y = fa[y][i]; return fa[x][0];
}

namespace sol1{ // n<=5000 20pts
	void sol(){
		for (int i(1), l, r, k; i<=q; ++i){
			cin >> l >> r >> k; set<pair<int, int>> st;
			for (int i(l); i<=l+k-1; ++i) st.insert({dfn[i], i}); int ans(dep[LCA(st.begin()->second, st.rbegin()->second)]);
			for (int i(l+1); i+k-1<=r; ++i){
				st.erase({dfn[i-1], i-1}); st.insert({dfn[i+k-1], i+k-1}); ans = max(ans, dep[LCA(st.begin()->second, st.rbegin()->second)]);
			}
			cout << ans << '\n';
		}
	}
}

namespace sol2{  // B 8pts
	int fmx[MAXN][MAXK], pmx[MAXN][MAXK], fmn[MAXN][MAXK], pmn[MAXN][MAXK];
	int qrymx(int l, int r){int k(__lg(r-l+1)); return fmx[l][k] > fmx[r-(1<<k)+1][k] ? pmx[l][k] : pmx[r-(1<<k)+1][k];}
	int qrymn(int l, int r){int k(__lg(r-l+1)); return fmn[l][k] < fmn[r-(1<<k)+1][k] ? pmn[l][k] : pmn[r-(1<<k)+1][k];}
	void sol(){
		for (int i(1); i<=n; ++i) fmx[i][0] = fmn[i][0] = dfn[i], pmn[i][0] = pmx[i][0] = i;
		for (int j(1); j<MAXK; ++j) for (int i(1); i+(1<<j)-1<=n; ++i){
			fmx[i][j] = max(fmx[i][j-1], fmx[i+(1<<(j-1))][j-1]); fmn[i][j] = min(fmn[i][j-1], fmn[i+(1<<(j-1))][j-1]);
			pmx[i][j] = fmx[i][j] == fmx[i][j-1] ? pmx[i][j-1] : pmx[i+(1<<(j-1))][j-1];
			pmn[i][j] = fmn[i][j] == fmn[i][j-1] ? pmn[i][j-1] : pmn[i+(1<<(j-1))][j-1];
		}
		for (int l, r, k; q; --q){
			cin >> l >> r >> k;
			cout << dep[LCA(qrymx(l, r), qrymn(l, r))] << '\n';
		}
	}
}

namespace sol3{
	namespace Seg{
		int cnt;
		struct Node{int lmx, rmx, ans, s;};
		struct Tr{Node p; int ls, rs;}tr[MAXN<<5];
		Node merge(Node a, Node b){
			Node c; c.s = a.s + b.s; c.lmx = a.s == a.lmx ? a.s+b.lmx : a.lmx; c.rmx = b.s == b.rmx ? b.s+a.rmx : b.rmx;
			c.ans = max({a.ans, b.ans, a.rmx+b.lmx}); return c;
		}
		void push_up(int p){tr[p].p = merge(tr[tr[p].ls].p, tr[tr[p].rs].p);}
		void build(int &p, int l, int r){
			p = ++cnt; if (l == r){tr[p].p = {0, 0, 0, 1}; return;} int mid((l+r)>>1);
			build(tr[p].ls, l, mid); build(tr[p].rs, mid+1, r); push_up(p);
		}
		void modify(int &p, int l, int r, int x){
			tr[++cnt] = tr[p]; p = cnt; if (l == r){tr[p].p = {1, 1, 1, 1}; return;} int mid((l+r)>>1);
			if (x <= mid) modify(tr[p].ls, l, mid, x); else modify(tr[p].rs, mid+1, r, x); push_up(p);
		}
		Node qry(int p, int l, int r, int L, int R){
			if (L <= l && r <= R) return tr[p].p; int mid((l+r)>>1); Node res = {0, 0, 0, 0};
			if (L <= mid) res = merge(res, qry(tr[p].ls, l, mid, L, R)); if (R > mid) res = merge(res, qry(tr[p].rs, mid+1, r, L, R));
			return res;
		}
	}
	int rt[MAXN], p[MAXN];
	bool chk(){
		int ct(0); for (int i(1); i<=n; ++i) if (e[i].size() == 1) ++ct; else if (e[i].size() > 2) return false;
		return ct == 2 && e[1].size() == 1;
	}
	void sol(){
		for (int i(1); i<=n; ++i) p[dep[i]] = i; Seg::build(rt[n+1], 1, n);
		for (int i(n); i; --i) Seg::modify(rt[i]=rt[i+1], 1, n, p[i]);
		for (int x, y, k; q; --q){
			cin >> x >> y >> k; int l(1), r(n), mid;
			while (l < r){
				mid = (l+r+1) >> 1; if (Seg::qry(rt[mid], 1, n, x, y).ans >= k) l = mid; else r = mid-1;
			}
			cout << l << '\n';
		}
	}
}

signed main(){
	freopen("query.in", "r", stdin); freopen("query.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	cin >> n; for (int i(1), u, v; i<n; ++i) cin >> u >> v, e[u].push_back(v), e[v].push_back(u); cin >> q; dfs(1, 0);
	for (int j(1); j<MAXK; ++j) for (int i(1); i<=n; ++i) fa[i][j] = fa[fa[i][j-1]][j-1];
	if (n <= 5000 && q <= 5000) sol1::sol(); else if (sol3::chk()) sol3::sol(); else sol2::sol();
	
	return 0;
}

// YYX!
