#include <bits/stdc++.h>
using namespace std;

const int maxn = 5e5 + 5;

int n, q;
struct Query {
    int l, r, k;
} Q[maxn];

int tot, h[maxn];
struct Edge {
    int v, nxt;
} e[maxn << 1];
void add(int u, int v) {
    e[++tot] = {v, h[u]}, h[u] = tot;
}

int clk, dfn[maxn], id[maxn], fa[maxn], dep[maxn];
void dfs(int u, int p) {
    dfn[u] = ++clk, id[clk] = u;
    fa[u] = p, dep[u] = dep[p] + 1;
    for (int i = h[u]; i; i = e[i].nxt)
        if (e[i].v != p) dfs(e[i].v, u);
}

int mn[20][maxn], mx[20][maxn], st[20][maxn], lg[maxn];
inline int Min(int l, int r) {
    int k = lg[r - l + 1];
    return min(mn[k][l], mn[k][r - (1 << k) + 1]);
}
inline int Max(int l, int r) {
    int k = lg[r - l + 1];
    return max(mx[k][l], mx[k][r - (1 << k) + 1]);
}
inline int calc(int u, int v) {
    if (u == v) return dep[id[u]];
    if (u > v) swap(u, v);
    int k = lg[v - u];
    return min(st[k][u + 1], st[k][v - (1 << k) + 1]) - 1;
}

namespace bf {
    void solve() {
        for (int t = 1; t <= q; ++t) {
            int l = Q[t].l, r = Q[t].r, k = Q[t].k, ans = 0;
            for (int i = l; i + k - 1 <= r; ++i)
                ans = max(ans, calc(Min(i, i + k - 1), Max(i, i + k - 1)));
            printf("%d\n", ans);
        }
    }
}

namespace B {
    bool check() {
        for (int t = 1; t <= q; ++t)
            if (Q[t].k != Q[t].r - Q[t].l + 1)
                return false;
        return true;
    }
    void solve() {
        for (int t = 1; t <= q; ++t) {
            int l = Q[t].l, r = Q[t].r;
            printf("%d\n", calc(Min(l, r), Max(l, r)));
        }
    }
}

namespace sol {
    const int maxn = 1e5 + 5;
    const int B = 80;
    int f[B + 2][17][maxn];
    inline int getans(int l, int r, int K) {
        int k = lg[r - l + 1];
        return max(f[K][k][l], f[K][k][r - (1 << k) + 1]);
    }
    void solve() {
        for (int len = 1; len <= B; ++len) {
            if (len > n) break;
            int m = n - len + 1;
            for (int i = 1; i <= m; ++i)
                f[len][0][i] = calc(i, i + len - 1);
            for (int i = 1; i <= lg[m]; ++i)
                for (int j = 1; j + (1 << i) - 1 <= m; ++j)
                    f[len][i][j] = max(f[len][i - 1][j], f[len][i - 1][j + (1 << (i - 1))]);
        }
        for (int t = 1; t <= q; ++t) {
            int l = Q[t].l, r = Q[t].r, k = Q[t].k;
            if (k <= B) printf("%d\n", getans(l, r - k + 1, k));
            else {
                int ans = 0;
                for (int i = l; i + k - 1 <= r; ++i)
                    ans = max(ans, calc(i, i + k - 1));
                printf("%d\n", ans);
            }
        }
    }
}

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);
        add(u, v), add(v, u);
    }
    scanf("%d", &q);
    for (int i = 1; i <= q; ++i)
        scanf("%d%d%d", &Q[i].l, &Q[i].r, &Q[i].k);
    dfs(1, 0);
    lg[0] = -1;
    for (int i = 1; i <= n; ++i) {
        mn[0][i] = mx[0][i] = dfn[i];
        st[0][dfn[i]] = dep[i];
        lg[i] = lg[i >> 1] + 1;
    }
    for (int i = 1; i <= lg[n]; ++i) {
        for (int j = 1; j + (1 << i) - 1 <= n; ++j) {
            int k = j + (1 << (i - 1));
            mn[i][j] = min(mn[i - 1][j], mn[i - 1][k]);
            mx[i][j] = max(mx[i - 1][j], mx[i - 1][k]);
            st[i][j] = min(st[i - 1][j], st[i - 1][k]);
        }
    }
    if (n <= 5000 && q <= 5000)
        bf::solve();
    else if (B::check())
        B::solve();
    else sol::solve();
    return 0;
}
