#include <bits/stdc++.h>

typedef long long ll;
typedef std::pair<int, int> pii;

template<typename T>
void read(T &r) { static char ch, last; ch = getchar(), last = 'z', r = 0; while (ch < '0' || ch > '9') last = ch, ch = getchar(); while (ch >= '0' && ch <= '9') r = (r << 1) + (r << 3) + (ch ^ 48), ch = getchar(); r = last == '-' ? -r : r; }
template<typename T, typename ...Ts>
void read(T &r, Ts& ...args) { read(r), read(args...); }

const int N = 1e5 + 10, M = 5e3 + 10;
int n;
std::vector<int> G[N];

int fa[N], sz[N], h[N], d[N], dt = 0;
void dfs1(int u, int f) {
    fa[u] = f; sz[u] = 1; h[u] = -1;
    for (int v : G[u]) {
        if (v == f) continue;
        d[v] = d[u] + 1;
        dfs1(v, u); sz[u] += sz[v];
        if (h[u] == -1 || sz[h[u]] < sz[v]) h[u] = v;
    }
}
int t[N];
void dfs2(int u, int tp) {
    t[u] = tp;
    if (~h[u]) dfs2(h[u], tp);
    for (int v : G[u]) {
        if (v == fa[u] || v == h[u]) continue;
        dfs2(v, v);
    }
}
int lca(int u, int v) {
    while (t[u] != t[v]) {
        if (d[t[u]] < d[t[v]]) std::swap(u, v);
        u = fa[t[u]];
    }
    if (d[u] < d[v]) std::swap(u, v);
    return v;
}

int ans[M][M], q;

namespace sub {
    bool check(int l, int r, int h, int k) {
        int cnt = 0;
        for (int i = l; i <= r; i++) {
            if (d[i] < h) cnt = 0;
            else cnt++;
            if (cnt >= k) return true;
        }
        return false;
    }
    void solve() {
        dfs1(1, 1);
        int q; read(q);
        while (q--) {
            int l, r, k; read(l, r, k);
            int x = 0, y = n - 1;
            while (x < y) {
                int mid = (x + y + 1) >> 1;
                if (check(l, r, mid, k)) x = mid;
                else y = mid - 1;
            }
            printf("%d\n", x + 1);
        }
    }
}

int main() {
    freopen("query.in", "r", stdin);
    freopen("query.out", "w", stdout);


    read(n);
    for (int i = 1; i < n; i++) {
        int u, v; read(u, v);
        G[u].push_back(v); G[v].push_back(u);
    }
    if (n > 5000) {
        sub::solve();
        return 0;
    }
    dfs1(1, 1); dfs2(1, 1);
    for (int i = 1; i <= n; i++) {
        ans[i][i] = i;
        int x = i;
        for (int j = i + 1; j <= n; j++) {
            x = lca(x, j);
            ans[i][j] = x;
        }
    }
    read(q);
    while (q--) {
        int l, r, k, x = 0;
        read(l, r, k);
        for (int i = l; i <= r - k + 1; i++) {
            x = std::max(x, d[ans[i][i + k - 1]]);
        }
        printf("%d\n", x + 1);
    }
    return 0;
}