#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr);
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
namespace fastio{
	template<typename T> inline void read(T &t){
		T x = 0, f = 1;
		char c = getchar();
		while(!isdigit(c)){
			if(c == '-') f = -f;
			c = getchar();
		}
		while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
		t = x * f;
	}
	template<typename T, typename ... Args> inline void read(T &t, Args &...args){
		read(t), read(args...);
	}
}
using namespace fastio;
const int N = 5e5 + 5, M = 5005;
int n, q;
vector<int> G[N];
int id, dfn[N], f[N][25], dep[N];
void dfs(int u, int fa){
	f[dfn[u] = ++id][0] = fa, dep[u] = dep[fa] + 1, dep[u] = dep[fa] + 1;
	for(auto &v : G[u]) if(v != fa) dfs(v, u);
}
int mindfn(int x, int y){return dfn[x] < dfn[y] ? x : y;}
void buildst(){
	_rep(i, 1, 20) _rep(j, 1, n - (1 << i) + 1) f[j][i] = mindfn(f[j][i - 1], f[j + (1 << i - 1)][i - 1]);
}
int lca(int x, int y){
	if(x == y) return x;
	x = dfn[x], y = dfn[y]; if(x > y) swap(x, y); x++;
	int k = __lg(y - x + 1);
	return mindfn(f[x][k], f[y - (1 << k) + 1][k]);
}
int g[M][M];
struct dsu{
	int fa[N];
	void init(){_rep(i, 1, n) fa[i] = i;}
	int find(int x){
		return fa[x] == x ? x : fa[x] = find(fa[x]);
	}
	void merge(int x, int y){
		int fx = find(x), fy = find(y);
		if(fx != fy) fa[fx] = fy;
	}
}d;
struct Query{
	int l, r, k;
}Q[N];
bool sol1 = 1, sol2 = 1;
namespace solution1{
	vector<pii> h[N];
	int p[N], ans[N];
	void solve1(){
		_rep(i, 1, q){
			int l = Q[i].l, r = Q[i].r;
			h[r].pb({l, i});
		}			
		d.init();
		_rep(i, 1, n){
			p[i] = i;
			int pos = i - 1;
			if(i > 1){
				int t = lca(p[i], p[i - 1]);
				int pos = i - 1, lst = 0;
				while(pos){
					int u = d.find(pos);
					if(dep[p[u]] < dep[t]) break;
					p[u] = t;
					if(lst) d.merge(lst, u);
					lst = u, pos = u - 1;
				}
			}
			for(auto &j : h[i]){
				int l = j.fi, id = j.se;
				ans[id] = dep[p[d.find(l)]];
			}
		}
		_rep(i, 1, q) printf("%d\n", ans[i]);
	}	
}
namespace solution2{
	int p[N];
	struct node{
		int ansl, ansr, ans, sum;
		node(int t = 0){ansl = ansr = ans = sum = t;}
		node operator+(const node b)const{
			node c;
			c.ans = max(ans, b.ans), c.ans = max(c.ans, ansr + b.ansl);
			c.sum = sum + b.sum;
			c.ansl = max(ansl, sum + b.ansl);
			c.ansr = max(ansr, ansr + b.sum);
			return c;
		}
	}tr[N * 25];
	int num, rt[N], ls[N * 25], rs[N * 25];
	void modify(int &x, int y, int l, int r, int p, int val){
		x = ++num, tr[x] = tr[y], ls[x] = ls[y], rs[x] = rs[y];
		if(l == r) return tr[x] = node(val), void();
		int mid = l + r >> 1;
		if(p <= mid) modify(ls[x], ls[y], l, mid, p, val);
		else modify(rs[x], rs[y], mid + 1, r, p, val);
		tr[x] = tr[ls[x]] + tr[rs[x]];
	}
	node query(int x, int l, int r, int L, int R){
		if(!x) return node();
		if(l >= L && r <= R) return tr[x];
		int mid = l + r >> 1;
		if(R <= mid) return query(ls[x], l, mid, L, R);
		if(L > mid) return query(rs[x], mid + 1, r, L, R);
		return query(ls[x], l, mid, L, R) + query(rs[x], mid + 1, r, L, R);
	}
	void solve(){
		_rep(i, 1, n) p[dep[i]] = i;
		_req(i, n, 1){
			modify(rt[i], rt[i + 1], 1, n, p[i], 1);
		}
		_rep(i, 1, q){
			int l, r, k; l = Q[i].l, r = Q[i].r, k = Q[i].k;
			int L = 1, R = n, res = 0;
			while(L <= R){
				int mid = L + R >> 1;
				if(query(rt[mid], 1, n, l, r).ans >= k) res = mid, L = mid + 1;
				else R = mid - 1;
			}
			printf("%d\n", res);
		}
	}
}
int main(){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	read(n);
	_rep(i, 2, n){
		int u, v; read(u, v);
		G[u].pb(v), G[v].pb(u);
	}
	dfs(1, 0), buildst();
	read(q);
	_rep(i, 1, q) read(Q[i].l, Q[i].r, Q[i].k), sol1 &= Q[i].k == Q[i].r - Q[i].l + 1;
	if(sol1) return solution1::solve1(), 0;
	int cnt1 = 0, cnt2 = 0;
	_rep(i, 1, n) cnt1 += G[i].size() == 1, cnt2 += G[i].size() == 2;
	if(cnt1 == 2 && cnt2 == n - 2) return solution2::solve(), 0;
	_rep(i, 1, n){
		g[i][i] = i;
		_rep(j, i + 1, n) g[i][j] = lca(g[i][j - 1], j);
	}
	_rep(i, 1, q){
		int l, r, k; l = Q[i].l, r = Q[i].r, k = Q[i].k;
		int ans = 0;
		_rep(i, l + k - 1, r) ans = max(ans, dep[g[i - k + 1][i]]);
		printf("%d\n", ans);
	}
	return 0;
}
/*
5
1 2
2 3
3 4
4 5
5
1 3 1
4 4 1
4 4 1
4 4 1
2 4 2

3
4
4
4
3

*/

