#include <bits/stdc++.h>
using namespace std;
const int M = 13000005, N = 500005;
int n, q, fa[N][20], dep[N], h[N], lg[N], rt[N], id[N];
vector <int> e[N], f[N];
struct ST{
	int mx[20][N];
	void init(int *h, int k = 1){
		for(int i = 1; i <= n; i++) mx[0][i] = h[i] * k;
		for(int i = 1; i <= 18; i++)
			for(int j = 1; j + (1 << i) - 1 <= n; j++)
				mx[i][j] = max(mx[i - 1][j], mx[i - 1][j + (1 << i - 1)]);
	} 
	int qry(int l, int r){
		int k = lg[r - l + 1];
		return max(mx[k][l], mx[k][r - (1 << k) + 1]);
	}
} D1, D2;
struct Val{ int lv, rv, mx, len;};
Val operator +(Val x, Val y){
	Val ans;
	if(x.lv == x.len) ans.lv = x.len + y.lv; else ans.lv = x.lv;
	if(y.rv == y.len) ans.rv = y.len + x.rv; else ans.rv = y.rv;
	ans.len = x.len + y.len, ans.mx = max(x.mx, max(y.mx, x.rv + y.lv));
	return ans;
}
struct sgt{
	int ls[M], rs[M], cnt; Val a[M];
	void build(int &x, int L, int R){
		a[x = ++cnt] = {0, 0, 0, R - L + 1};
		if(L == R) return ;
		build(ls[x], L, L + R >> 1), build(rs[x], L + R + 2 >> 1, R); 
	}
	void mdf(int p, int &x, int L, int R, int k){
		x = ++cnt, a[x] = {0, 0, 0, R - L + 1};
		if(L == R) return a[x] = {1, 1, 1, 1}, void();
		int mid = L + R >> 1;
		if(k <= mid) mdf(ls[p], ls[x], L, mid, k), rs[x] = rs[p];
		else mdf(rs[p], rs[x], mid + 1, R, k), ls[x] = ls[p];
		a[x] = a[ls[x]] + a[rs[x]];
	}
	Val qry(int x, int L, int R, int l, int r){
		if(L >= l && R <= r) return a[x];
		int mid = L + R >> 1;
		if(l > mid) return qry(rs[x], mid + 1, R, l, r);
		if(r <= mid) return qry(ls[x], L, mid, l, r);
		return qry(ls[x], L, mid, l, r) + qry(rs[x], mid + 1, R, l, r);
	}
} T;
void dfs(int x, int p){
	dep[x] = dep[p] + 1, fa[x][0] = p;
	for(int i = 1; i <= 19; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];
	for(int i: e[x]) if(i != p) dfs(i, x);
}
int lca(int x, int y){
	if(dep[x] < dep[y]) swap(x, y);
	for(int i = 19; i >= 0; i--) if(dep[fa[x][i]] >= dep[y]) x = fa[x][i];
	for(int i = 19; i >= 0; i--) if(fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
	return x == y? x: fa[x][0];
}
int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	cin >> n;
	for(int i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1;
	for(int i = 1, u, v; i < n; i++) cin >> u >> v, e[u].push_back(v), e[v].push_back(u);
	dfs(1, 0);
	for(int i = 1; i <= n; i++) h[i] = dep[i];
	D1.init(h); int mx = 0;
	for(int i = 1; i < n; i++) h[i] = dep[lca(i, i + 1)], mx = max(mx, h[i]);
	D2.init(h, -1);
	for(int i = 1; i < n; i++) f[h[i]].push_back(i);
	T.build(rt[0], 1, n); int now = 0;
	for(int i = n; i; i--){
		for(int j: f[i]) T.mdf(rt[now], rt[now + 1], 1, n, j), now++;
		id[i] = now;
	}
	cin >> q; int hh = 0;
	while(q--){
		int l, r, k; cin >> l >> r >> k;
		if(k == 1){ cout << D1.qry(l, r) << '\n'; continue;}
		if(k == r - l + 1){ cout << -D2.qry(l, r - 1) << '\n'; continue;}
		int L = 1, R = mx;
		while(L < R){
			int mid = L + R + 1 >> 1;
			if(T.qry(rt[id[mid]], 1, n, l, r - 1).mx < k - 1) R = mid - 1;
			else L = mid;
		}
		cout << L << '\n'; 
	}
	return 0;
}
