#include <bits/stdc++.h>
#define N 500010
using namespace std;
int n, q;
int head[N], nxt[N * 2], to[N * 2], cnt;
void addEdge(int u, int v) {
    cnt ++;
    to[cnt] = v;
    nxt[cnt] = head[u];
    head[u] = cnt;
}
int dep[N], fa[N][19];
void dfs(int u, int f) {
    dep[u] = dep[f] + 1;
    fa[u][0] = f;
    for(int i = 1; i <= 18; i ++) {
        fa[u][i] = fa[fa[u][i-1]][i-1];
    }
    for(int i = head[u]; i; i = nxt[i]) {
        int v = to[i];
        if(v == f) continue;
        dfs(v, u);
    }
}
int lca(int u, int v) {
    if(dep[u] < dep[v]) swap(u, v);
    for(int i = 18; i >= 0; i --) {
        if(dep[fa[u][i]] >= dep[v]) {
            u = fa[u][i];
        }
    }
    if(u == v) return u;
    for(int i = 18; i >= 0; i --) {
        if(fa[u][i] != fa[v][i]) {
            u = fa[u][i];
            v = fa[v][i];
        }
    }
    return fa[u][0];
}
int t[N * 4];
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
void build(int l, int r, int pos) {
    if(l == r) {
        t[pos] = l;
        return;
    }
    int mid = (l + r) >> 1;
    build(l, mid, ls(pos));
    build(mid + 1, r, rs(pos));
    t[pos] = lca(t[ls(pos)], t[rs(pos)]);
}
int query(int nl, int nr, int l, int r, int pos) {
    if(nl <= l && r <= nr) {
        return t[pos];
    }
    int mid = (l + r) >> 1;

    if(nl <= mid && mid < nr) return lca(query(nl, nr, l, mid, ls(pos)), query(nl, nr, mid + 1, r, rs(pos)));
    if(nl <= mid) return query(nl, nr, l, mid, ls(pos));
    if(mid < nr) return query(nl, nr, mid + 1, r, rs(pos));
    return 0;
}
int main() {
    freopen("query.in", "r", stdin);
    freopen("query.out", "w", stdout);
    scanf("%d", &n);
    for(int i = 1; i < n; i ++) {
        int u, v;
        scanf("%d %d", &u, &v);
        addEdge(u, v);
        addEdge(v, u);
    }
    dfs(1, 0);
    build(1, n, 1);
    scanf("%d", &q);
    for(int i = 1; i <= q; i ++) {
        int l, r, k;
        scanf("%d %d %d", &l, &r, &k);
        int ans = 0, de = 0;
        if(n <= 5000 || r - l + 1 == k) {
            for(int j = l; j <= r - k + 1; j ++) {
                int res = query(j, j + k - 1, 1, n, 1);
                if(dep[res] > de) {
                    de = dep[res];
                    ans = res;
                }
            }
        } else {
            for(int j = l; j <= r - k + 1 && j - l <= 500; j ++) {
                int res = query(j, j + k - 1, 1, n, 1);
                if(dep[res] > de) {
                    de = dep[res];
                    ans = res;
                }
            }
        }
        printf("%d\n", de);
    }
}