#include <bits/stdc++.h>
using namespace std;
int read() {
    char ch = getchar();
    int x = 0;
    while (ch < '0' || ch > '9') ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    return x;
}

// bool _S;

namespace Solve {
    const int M = 5e5 + 10;

    int n, q, a[M], mxdep;
    vector<int> g[M];

    int fa[M], son[M], siz[M], dep[M], top[M];
    void dfs1(int u, int f) {
        fa[u] = f, siz[u] = 1, dep[u] = dep[f] + 1;
        mxdep = max(mxdep, dep[u]);
        for (int v : g[u]) {
            if (v == f) continue;
            dfs1(v, u), siz[u] += siz[v];
            if (siz[v] > siz[son[u]]) son[u] = v;
        }
    }
    int dfn[M], idx;
    int dfnmin(int x, int y) {
        return dfn[x] < dfn[y] ? x : y;
    }
    void dfs2(int u, int t) {
        top[u] = t, dfn[u] = ++idx;
        if (son[u]) dfs2(son[u], t);
        for (int v : g[u])
            if (v != fa[u] && v != son[u]) dfs2(v, v);
    }
    int LCA(int u, int v) {
        while (top[u] ^ top[v]) {
            if (dep[top[u]] < dep[top[v]]) swap(u, v);
            u = fa[top[u]];
        }
        return dep[u] < dep[v] ? u : v;
    }

    namespace B {
        int st[20][M];
        void build() {
            for (int i = 1; i <= n; i++) st[0][dfn[i]] = fa[i];
            for (int j = 1; (1 << j) <= n; j++)
                for (int i = 1; i + (1 << j) - 1 <= n; i++)
                    st[j][i] = dfnmin(st[j - 1][i], st[j - 1][i + (1 << j - 1)]);
        }
        int Lca(int u, int v) {
            if (u == v) return u;
            if ((u = dfn[u]) > (v = dfn[v])) swap(u, v);
            int k = log2(v - u);
            return dfnmin(st[k][u + 1], st[k][v - (1 << k) + 1]);
        }
        
        int lca[20][M];
        void _build() {
            for (int i = 1; i <= n; i++) lca[0][i] = i;
            for (int j = 1; (1 << j) <= n; j++)
                for (int i = 1; i + (1 << j) - 1 <= n; i++)
                    lca[j][i] = Lca(lca[j - 1][i], lca[j - 1][i + (1 << j - 1)]);
        }
        int ask(int l, int r) {
            int k = log2(r - l + 1);
            return Lca(lca[k][l], lca[k][r - (1 << k) + 1]);
        }
    }

    namespace SEG {
        struct Node {
            int l, r, f, fl, fr;
            bool v;
        } tr[M << 2];
        inline Node merge(Node A, Node B) {
            Node C;
            C.l = A.l, C.r = B.r, C.v = B.v;
            C.f = max(A.f, B.f);
            if (A.v) C.f = max(C.f, A.fr + B.fl);
            if (A.fl == A.r - A.l + 1 && A.v) C.fl = A.fl + B.fl;
            else C.fl = A.fl;
            if (B.fr == B.r - B.l + 1 && A.v) C.fr = B.fr + A.fr;
            else C.fr = B.fr;
            return C;
        }
        inline void build(int k, int l, int r) {
            tr[k].l = l, tr[k].r = r;
            if (l == r) {
                tr[k].f = tr[k].fl = tr[k].fr = 0;
                tr[k].v = false;
                return ;
            }
            int mid = (l + r) >> 1;
            build(k << 1, l, mid), build(k << 1 | 1, mid + 1, r);
            tr[k] = merge(tr[k << 1], tr[k << 1 | 1]);
        }
        inline void upd(int k, int x, bool v) {
            if (tr[k].l == tr[k].r) {
                tr[k].v = v;
                return ;
            }
            int mid = (tr[k].l + tr[k].r) >> 1;
            upd(k << 1 | (x > mid), x, v);
            tr[k] = merge(tr[k << 1], tr[k << 1 | 1]);
        }
        inline void _upd(int k, int x, int v) {
            if (tr[k].l == tr[k].r) {
                tr[k].f = tr[k].fl = tr[k].fr = v;
                return ;
            }
            int mid = (tr[k].l + tr[k].r) >> 1;
            _upd(k << 1 | (x > mid), x, v);
            tr[k] = merge(tr[k << 1], tr[k << 1 | 1]);
        }
        inline Node ask(int k, int l, int r) {
            if (l <= tr[k].l && tr[k].r <= r) return tr[k];
            int mid = (tr[k].l + tr[k].r) >> 1;
            if (r <= mid) return ask(k << 1, l, r);
            if (l > mid)  return ask(k << 1 | 1, l, r);
            return merge(ask(k << 1, l, r), ask(k << 1 | 1, l, r));
        }
    }

    struct Node {
        int l, r, k;
    } Q[M];
    int ans[M];
    vector<int> pos[M], dpos[M];
    inline void solve(int l, int r, vector<int>& q) {
        if (q.empty()) return ;
        if (l == r) {
            for (int x : q) ans[x] = l;
            return ;
        }
        int mid = (l + r) >> 1;
        
        for (int x = r; x > mid; x--) {
            for (int i : dpos[x]) SEG::_upd(1, i, 1);
            for (int i : pos[x]) SEG::upd(1, i, 1);
        }
        vector<int> ql, qr;
        for (int x : q) {
            if (SEG::ask(1, Q[x].l, Q[x].r).f >= Q[x].k) qr.emplace_back(x);
            else ql.emplace_back(x);
        }
        solve(l, mid, ql);
        for (int x = r; x > mid; x--) {
            for (int i : pos[x]) SEG::upd(1, i, 0);
            for (int i : dpos[x]) SEG::_upd(1, i, 0);
        }
        solve(mid + 1, r, qr);
    }

    namespace Sol0 {
        const int N = M * 20;
        int lc[N], rc[N], sum[N], rt[M], cnt;
        void ins(int& k, int pre, int l, int r, int x) {
            sum[k = ++cnt] = sum[pre] + 1;
            lc[k] = lc[pre], rc[k] = rc[pre];
            if (l == r) return ;
            int mid = (l + r) >> 1;
            if (x <= mid) ins(lc[k], lc[pre], l, mid, x);
            else ins(rc[k], rc[pre], mid + 1, r, x);
        }
        int ask(int k1, int k2, int l, int r, int res) {
            if (l == r) {
                assert(sum[k2] - sum[k1] >= res);
                return l;
            }
            int mid = (l + r) >> 1, t = sum[rc[k2]] - sum[rc[k1]];
            if (t >= res) return ask(rc[k1], rc[k2], mid + 1, r, res);
            return ask(lc[k1], lc[k2], l, mid, res - t);
        }

        void mian() {
            // fprintf(stderr, "1\n");
            for (int i = 1; i <= n; i++)
                ins(rt[i], rt[i - 1], 1, n, dep[i]);
            for (int i = 1; i <= q; i++)
                ans[i] = ask(rt[Q[i].l - 1], rt[Q[i].r], 1, n, Q[i].k);
            return ;
        }
    }

    void mian() {
        n = read();
        for (int i = 1, u, v; i < n; i++) {
            u = read(), v = read();
            g[u].emplace_back(v);
            g[v].emplace_back(u);
        }
        dfs1(1, 0), dfs2(1, 1);
        B::build(), B::_build();
        for (int i = 1; i < n; i++) a[i] = dep[LCA(i, i + 1)]/* , printf("a[%d] = %d\n", i, a[i]) */;
        a[n] = 1145141919;
        for (int i = 1; i < n; i++) pos[a[i]].emplace_back(i);
        for (int i = 1; i <= n; i++) dpos[dep[i]].emplace_back(i);
        SEG::build(1, 1, n);
        // fprintf(stderr, "mxdep = %d\n", mxdep);

        q = read();
        vector<int> _q;
        for (int i = 1; i <= q; i++) {
            Q[i].l = read(), Q[i].r = read(), Q[i].k = read();
            if (Q[i].k == Q[i].r - Q[i].l + 1) ans[i] = dep[B::ask(Q[i].l, Q[i].r)];
            else _q.emplace_back(i);
        }
        if (mxdep == n) Sol0::mian();
        else solve(1, mxdep, _q);
        for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
        return ;
    }
}

// bool _E;

int main() {
    // fprintf(stderr, "%ld\n", (&_E - &_S) / 1024 / 1024);
    // double st = clock();
    freopen("query.in", "r", stdin);
    freopen("query.out", "w", stdout);
    Solve::mian();
    // double ed = clock();
    // fprintf(stderr, "%d\n", int(ed - st));
    return 0;
}