#include <bits/stdc++.h>
#define FileIO_(file) \
    freopen (file ".in", "r", stdin); \
    freopen (file ".out", "w", stdout);

using namespace std;

namespace Main {

namespace IO {

void read () {}

template<typename Tp, typename... Args>
void read (Tp &x, Args&... rest) {
    int c = getchar (); x = 0;
    while (!isdigit (c)) c = getchar ();
    do x = (x << 1) + (x << 3) + (c & 15);
    while (isdigit (c = getchar ()));
    read (rest...);
}

template<typename Tp>
void write (Tp x) {
    static int top, wr[50];
    do wr[++top] = x % 10; while (x /= 10);
    while (top) putchar (wr[top--] | 48);
}

} // namespace IO

template<typename Tp>
void chmax (Tp &x, const Tp &y) { x = max (x, y); }

using namespace IO;
using ll = long long;

const int maxn = 5e5 + 20;
const int maxq = 5e5 + 20;
int n, q, ans[maxq];

int ds[maxn];

int dsfind (int u) {
    return u != ds[u] ? ds[u] = dsfind (ds[u]) : u;
}

int dep[maxn], lcadep[maxn];

vector<int> g[maxn];

void dfs (int u, int f) {
    dep[u] = dep[f] + 1;
    if (ds[u - 1]) {
        lcadep[u - 1] = dep[dsfind (u - 1)];
    }
    if (ds[u + 1]) {
        lcadep[u] = dep[dsfind (u + 1)];
    }
    ds[u] = u;
    for (int v : g[u]) {
        if (v != f) {
            dfs (v, u);
            ds[v] = u;
        }
    }
}

struct Info {
    int l, r, k, id;
    Info (int l, int r, int k, int id):
        l (l), r (r), k (k), id (id) {}
};

vector<Info> vec;

int ls[maxn], rs[maxn];
stack<int> stk;

void dfs (int u, int l, int r) {
    vec.emplace_back (l, r, r - l + 1, -lcadep[u]);
    if (ls[u]) dfs (ls[u], l, u);
    if (rs[u]) dfs (rs[u], u + 1, r);
}

int tmr, tr[maxn], vis[maxn];

void upd (int p, int v) {
    while (p <= n) {
        if (vis[p] != tmr) {
            tr[p] = v;
            vis[p] = tmr;
        } else {
            chmax (tr[p], v);
        }
        p += p & -p;
    }
}

int qry (int p) {
    int res = 0;
    while (p) {
        if (vis[p] == tmr) {
            chmax (res, tr[p]);
        }
        p &= p - 1;
    }
    return res;
}

void cdq (int l, int r) {
    if (l + 1 == r) return;
    int mid = (l + r) >> 1;
    cdq (l, mid); cdq (mid, r);
    int i = l, j = mid; ++tmr;
    while (j < r) {
        while (i < mid && vec[i].r >= vec[j].r) {
            if (vec[i].id < 0) {
                // auto item = vec[i];
                // cerr << item.l<<" "<<item.r<<" "<<item.k<<" "<<item.id<<endl;
                upd (vec[i].l, -vec[i].id);
            }
            ++i;
        }
        if (vec[j].id > 0) {
            // auto item = vec[j];
            // cerr << item.l<<" "<<item.r<<" "<<item.k<<" "<<item.id<<endl;
            chmax (ans[vec[j].id], qry (vec[j].l));
        }
        ++j;
    }
    // cerr<<endl;
    inplace_merge (
        vec.begin () + l,
        vec.begin () + mid,
        vec.begin () + r,
        [] (const auto &lhs, const auto &rhs) {
            return lhs.r > rhs.r;
        }
    );
}

void solve () {
    read (n);
    for (int i = 1, u, v; i < n; ++i) {
        read (u, v);
        g[u].emplace_back (v);
        g[v].emplace_back (u);
    }
    dfs (1, 0);
    stk.emplace (0);
    for (int i = 1; i < n; ++i) {
        while (lcadep[i] < lcadep[stk.top ()]) {
            rs[stk.top ()] = ls[i];
            ls[i] = stk.top ();
            stk.pop ();
        }
        rs[stk.top ()] = i;
        stk.emplace (i);
    }
    dfs (1, 1, n);
    for (int i = 1; i <= n; ++i) {
        vec.emplace_back (i, i, 1, -dep[i]);
    }
    read (q);
    for (int i = 1, l, r, k; i <= q; ++i) {
        read (l, r, k);
        vec.emplace_back (r - k + 1, l + k - 1, k, i);
    }
    sort (vec.begin (), vec.end (),
        [] (const auto &lhs, const auto &rhs) {
            return lhs.k != rhs.k ?
                lhs.k > rhs.k : lhs.id < rhs.id;
        }
    );
    cdq (0, vec.size ());
    for (int i = 1; i <= q; ++i) {
        write (ans[i]); putchar (10);
    }
}

int main () {
    solve ();
    return 0;
}

} // namespace Main

int main () {
    FileIO_("query");
    return Main::main ();
}