#include<bits/stdc++.h>
#define ll long long
#define Mid ll mid = (l+r)>>1
using namespace std;
const int N = 5e5 + 20, Mod = 1e9+7, M = 5200;
ll T, n, m, q, s = 1, f[N][25], dep[N], maxx = 0;
struct node{
	ll l, r, k;
}a[N];
ll ans[M][M];
vector<ll> G[N];
struct segtree{
	ll p;
}tree[N<<2];
ll ls(ll x){return x<<1;}
ll rs(ll x){return x<<1|1;}

void add_edge(ll u, ll v) {G[u].push_back(v);}
void dfs(ll u, ll fa) {
	dep[u] = dep[fa] + 1;
	f[u][0] = fa;
	for(int i = 0; i < G[u].size(); i++){
		ll v = G[u][i];
		if(v == fa) continue;
		dfs(v, u);
//		f[v][0] = u;
	}
}
void init(){
	for(int j = 1; j <= 20; j++){
		for(int i = 1; i <= n; i++) {
			f[i][j] = f[f[i][j-1]][j-1];
		}
	}
}
ll LCA(ll x, ll y) {
	if(x == -1) return y;
	if(y == -1) return x;
	if(dep[x] < dep[y]) swap(x, y);
	for(int i = 20; i >= 0; i--) {
		if(dep[f[x][i]] >= dep[y]) x = f[x][i];
	}
	if(x == y) return x;
	for(int i = 20; i >= 0; i--) {
		if(dep[f[x][i]] != dep[f[y][i]]) x = f[x][i], y = f[y][i];
	}
	return f[x][0];
}
void build(ll p, ll l, ll r) {
	if(l == r) {
		tree[p].p = l;
		return ;
	}
	Mid;
	build(ls(p), l, mid);
	build(rs(p), mid+1, r);
	tree[p].p = LCA(tree[ls(p)].p, tree[rs(p)].p);
	return ;
}
ll query(ll p, ll l, ll r, ll x, ll y) {
	if(x <= l && r <= y) {return tree[p].p;}
	Mid;
	ll res = -1;
	if(x <= mid) res = LCA(res, query(ls(p), l, mid, x, y));
	if(y >  mid) res = LCA(res, query(rs(p), mid+1, r, x, y));
//	tree[p].p = LCA(tree[ls(p)].p, tree[rs(p)].p);
	return res;
}
int main(){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
		scanf("%lld", &n);
		for(int i = 1; i < n; i++) {
			ll u, v;
			scanf("%lld%lld", &u, &v);
			add_edge(u, v);
			add_edge(v, u);
		}
		dfs(s, 0);
		init();
		
		scanf("%lld", &q);
		if(n <= 5000 && q <= 5000){
			for(int i = 1;  i <= n; i++) {
				ans[i][i] = i;
				for(int j = i+1; j <= n; j++) {
					ans[i][j] = LCA(ans[i][j-1], j);
				}
			}
			for(int z = 1; z <= q; z++) {
			ll l, r, k;
			maxx = 0;
			scanf("%lld%lld%lld", &l, &r, &k);
			for(int i = l; i+k-1 <= r; i++) {
				ll x = i, y = i+k-1;
				maxx = max(maxx, dep[ans[x][y]]);
			}
			printf("%lld\n", maxx);
		}
		}
		else 
		{
			ll cnt = 0;
			for(int i = 1; i <= q; i++) {
			scanf("%lld%lld%lld", &a[i].l, &a[i].r, &a[i].k);
			if(a[i].r - a[i].l+1 == a[i].k) cnt ++;
		}
			if(cnt == q) {
				build(1, 1, n);
				for(int i = 1; i <= q; i++) {
				maxx = dep[query(1, 1, n, a[i].l, a[i].r)];
				printf("%lld\n", maxx);
				}
			}
		}
	
	return 0;
} 
