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

#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define per(i, a, b) for(int i = (a); i >= (b); --i)
bool Mst;

const int maxn = 5e5 + 10005;

int n, q;
vector<int> e[maxn];
struct node{
	int l, r, k, id;
}Q[maxn];

namespace sub1{
	
	const int maxn = 5005;
		
	struct tree{
		int ch[2];
		int pre, suf, mx, sz, len;
		tree(){ ch[0] = ch[1] = pre = suf = mx = sz = len = 0; }
	}t[maxn * 30]; int tot;
	
	#define ls (t[x].ch[0])
	#define rs (t[x].ch[1])
	
	inline void up(int x){
		if(!x) return;
		t[x].sz = t[ls].sz + t[rs].sz;
		t[x].pre = t[ls].pre, t[x].suf = t[rs].suf;
		
		if(ls and t[ls].pre == t[ls].len) t[x].pre = t[ls].len + t[rs].pre;
		if(rs and t[rs].suf == t[rs].len) t[x].suf = t[ls].suf + t[rs].len;
		
		t[x].mx = max(t[ls].suf + t[rs].pre, max(t[ls].mx, t[rs].mx));
	}
	inline int Merge(int x, int y, int l, int r){
		if(!x or !y) return x + y;
		if(l == r){
			if(t[x].sz) return x; else return y;
		}
		int mid = l + r >> 1;
		ls = Merge(ls, t[y].ch[0], l, mid), 
		rs = Merge(rs, t[y].ch[1], mid + 1, r);
		t[x].len = r - l + 1;
		up(x);
		return x;
	}
	inline void Updt(int &x, int l, int r, int p, int v){
		if(true){
			x = ++tot, t[x].len = r - l + 1;
			t[x].sz = t[x].ch[0] = t[x].ch[1] = t[x].suf = t[x].pre = t[x].mx = 0;
		} 
		if(l == r){
			t[x].ch[0] = t[x].ch[1] = 0;
			t[x].len = 1;
			t[x].pre = t[x].suf = t[x].mx = t[x].sz = v;
			return;
		} 
		int mid = l + r >> 1;
		if(p <= mid) Updt(ls, l, mid, p, v); 
		else Updt(rs, mid + 1, r, p, v);
		up(x);
	}
	
	int Ans, dep[maxn], rt[maxn], L, R, K;

	inline void dfs(int x, int fa){
		dep[x] = dep[fa] + 1;
		Updt(rt[x], 1, n, x, (x >= L and x <= R));
		
		for(int v : e[x]) if(v != fa)
			dfs(v, x), rt[x] = Merge(rt[x], rt[v], 1, n);
		if(t[rt[x]].mx >= K) 
			Ans = max(Ans, dep[x]);
		
//		cout << x << " " << t[rt[x]].mx << " " << t[rt[x]].sz << '\n'; 
	}
	
	inline void slv(){
		rep(o, 1, q){
			L = Q[o].l, R = Q[o].r, K = Q[o].k;
			tot = 0; rep(i, 1, n) rt[i] = 0; Ans = 1;
			
			dfs(1, 0);
			
			cout << Ans << '\n';
		}
	}
}

namespace sub2{
	
	int dfn[maxn], tot, fa[maxn][21], dep[maxn], rv[maxn];
	
	inline void dfs(int x, int f){
		dfn[x] = ++tot; fa[x][0] = f; dep[x] = dep[f] + 1; rv[tot] = x;
		rep(i, 1, 20) fa[x][i] = fa[fa[x][i - 1]][i - 1];
		for(int v : e[x]) if(v != f)
			dfs(v, x);
	}
	inline int LCA(int x, int y){
		if(dep[x] < dep[y]) swap(x, y);
		per(i, 20, 0) if(dep[fa[x][i]] >= dep[y]) x = fa[x][i];
		if(x == y) return x;
		per(i, 20, 0) if(fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
		return fa[x][0];
	}
	
	int st[2][21][maxn];
	inline void init(){
		rep(o, 0, 1) rep(i, 1, n) st[o][0][i] = dfn[i];
		for(int j = 1; (1 << j) <= n; ++j) for(int i = 1; i + (1 << j) - 1 <= n; ++i)
			st[0][j][i] = min(st[0][j - 1][i], st[0][j - 1][i + (1 << j - 1)]),
			st[1][j][i] = max(st[1][j - 1][i], st[1][j - 1][i + (1 << j - 1)]);
	}
	inline int qry_mn(int l, int r){
		int k = log2(r - l + 1);
		return min(st[0][k][l], st[0][k][r - (1 << k) + 1]);
	}
	inline int qry_mx(int l, int r){
		int k = log2(r - l + 1);
		return max(st[1][k][l], st[1][k][r - (1 << k) + 1]);
	}
	
	inline void slv(){
		dfs(1, 0);
		init();
		rep(i, 1, q){
			int l = Q[i].l, r = Q[i].r, k = Q[i].k;
			cout << dep[LCA(rv[qry_mn(l, r)], rv[qry_mx(l, r)])] << '\n'; 
		}
	}
}

namespace sub3{
	
	int dep[maxn], ans[maxn], rv[maxn];
	
	inline void dfs(int x, int fa){
		dep[x] = dep[fa] + 1; rv[dep[x]] = x;
		for(int v : e[x]) if(v != fa) dfs(v, x);
	}
	
	struct tree{
		int pre, suf, sz, len, mx, op;
		tree(){ pre = suf = sz = len = mx = op = 0; }
	}t[maxn << 2];
	
	#define ls (x << 1)
	#define rs (x << 1 | 1)
	
	inline tree Merge(tree l, tree r){
		tree x;
		x.sz = l.sz + r.sz;
		x.pre = l.pre, x.suf = r.suf;
		if(l.op) x.pre = l.sz + r.pre;
		if(r.op) x.suf = l.suf + r.sz;
		x.mx = max(l.suf + r.pre, max(l.mx, r.mx));
		if(l.op == 1 and r.op == 1) x.op = 1; else x.op = 0;
		return x;
	}
	inline void up(int x, int len){
		t[x] = Merge(t[ls], t[rs]); t[x].len = len;
	}
	inline void updtp(int x, int l, int r, int p, int v){
//		t[x].len = r - l + 1;
		if(l == r){
			t[x].pre = t[x].suf = t[x].sz = t[x].mx = t[x].op = v;
			return;
		}
		int mid = l + r >> 1;
		if(p <= mid) updtp(ls, l, mid, p, v);
		else updtp(rs, mid + 1, r, p, v);
		up(x, r - l + 1);
	}
	inline tree qryr(int x, int l, int r, int L, int R){
		if(l >= L and r <= R) return t[x];
		int mid = l + r >> 1;
		if(R <= mid) return qryr(ls, l, mid, L, R);
		if(L > mid) return qryr(rs, mid + 1, r, L, R);
		return Merge(qryr(ls, l, mid, L, R), qryr(rs, mid + 1, r, L, R));
	}
	
	inline void Solve(int L, int R, vector<node> qs){
		if(L > R or !qs.size()) return;
		if(L == R){
			for(node nw : qs) ans[nw.id] = L;
			return; 
		}
		int mid = L + R >> 1;
		
		rep(i, mid + 1, R) updtp(1, 1, n, rv[i], 1);
		vector<node> Ls, Rs; Ls.clear(), Rs.clear();
		for(node nw : qs){
			tree x = qryr(1, 1, n, nw.l, nw.r);
			if(x.mx >= nw.k) Rs.push_back(nw);
			else Ls.push_back(nw);
		}
		
		Solve(L, mid, Ls);
		rep(i, mid + 1, R) updtp(1, 1, n, rv[i], 0);
		Solve(mid + 1, R, Rs);
	}
	
	inline void slv(){
		dfs(1, 0);
		vector<node> Tmp; rep(i, 1, q) Tmp.push_back(Q[i]);
		Solve(1, n, Tmp);
		rep(i, 1, q) cout << ans[i] << '\n';
	}
}

bool Med;
signed main(){
//	return system("fc query4.ans query.out"), 0;
	
	freopen("query.in", "r", stdin); freopen("query.out", "w", stdout);
	
	fprintf(stderr, "%.2lfMB\n", abs(&Mst - &Med) / 1024. / 1024.);
	
	ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL);
	
	cin >> n;
	rep(i, 2, n){
		int u, v; cin >> u >> v;
		e[u].push_back(v), e[v].push_back(u);
	}
	cin >> q;
	rep(i, 1, q) cin >> Q[i].l >> Q[i].r >> Q[i].k, Q[i].id = i;
	
	if(n <= 5e3 and q <= 5e3) return sub1::slv(), 0;
	
	int flg = 0;
	rep(i, 1, q) if(Q[i].k != Q[i].r - Q[i].l + 1) flg = 1;
	if(!flg) return sub2::slv(), 0;
	
	return sub3::slv(), 0;
	return 0;
}
/*
6
1 2
2 3
3 4
4 5
5 6
3
2 5 3
1 4 2
1 6 4

3
3
3
*/
