#include <bits/stdc++.h>

constexpr size_t N = 5 * 1e5 + 1;

template <typename T>
void read(T &x)
{
    x = 0;
    T f = 1;
    char ch = getchar();
    while (!isdigit(ch))
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (isdigit(ch))
    {
        x = (x << 3) + (x << 1) + (ch ^ 48);
        ch = getchar();
    }
    x *= f;
}

template <typename T, typename... Tp>
void read(T &x, Tp &...rest)
{
    read(x);
    read(rest...);
}

template <typename T>
void write(T x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }

    if (x >= 10)
        write(x / 10);
    putchar(x % 10 + '0');
}

std::array<std::vector<int>, N> E;
std::array<int, N> deg;
void insert(int u, int v)
{
    E[u].emplace_back(v);
    E[v].emplace_back(u);
}

int n, q;

std::array<int, N> dep, fa, son, size, top;
void dfs1(int u)
{
    dep[u] = dep[fa[u]] + 1;
    size[u] = 1;
    son[u] = -1;

    for (auto v : E[u])
        if (v != fa[u])
        {
            fa[v] = u;
            dfs1(v);
            size[u] += size[v];
            if (son[u] == -1 || size[v] > size[son[u]])
                son[u] = v;
        }
}

void dfs2(int u, int t)
{
    top[u] = t;

    if (son[u] != -1)
        dfs2(son[u], t);

    for (auto v : E[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]])
            std::swap(u, v);

        u = fa[top[u]];
    }
    return dep[u] < dep[v] ? u : v;
}

std::array<std::array<int, 20>, N> st;

std::array<int, N> lg2;
void build()
{
    for (int i = 1; i <= n; ++i)
        st[i][0] = i;

    for (int j = 1; j <= lg2[n]; ++j)
        for (int i = 1; i + (1 << j) - 1 <= n; ++i)
            st[i][j] = lca(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
}

int main()
{
    freopen("query.in", "r", stdin);
    freopen("query.out", "w", stdout);
    read(n);
    for (int i = 2; i <= n; ++i)
        lg2[i] = lg2[i / 2] + 1;

    for (int i = 1; i < n; ++i)
    {
        int u, v;
        read(u, v);
        deg[u]++, deg[v]++;
        insert(u, v);
    }

    // bool flag = false;
    // if (deg[1] == 1)
    // {
    //     int cnt{};
    //     for (int i = 1; i <= n; ++i)
    //         if (deg[i] == 2)
    //             ++cnt;
    //     if (cnt == n - 2)
    //         flag = true;
    // }

    // if (!flag)
    // {
        dfs1(1);
        dfs2(1, 1);
        build();
    // }
    // else
    // {
    //     dep[1] = 1;
    //     int v = 1, u = E[1][0];
    //     while (E[u].size() != 1)
    //     {
    //         dep[u] = dep[v] + 1;
    //         for (auto vv : E[u])
    //             if (vv != v)
    //                 u = vv;
    //     }

    //     for (int i = 1; i <= n; ++i)
    //         st[i][0] = dep[i];

    //     for (int j = 1; j <= lg2[n]; ++j)
    //         for (int i = 1; i + (1 << j) - 1 <= n; ++i)
    //             st[i][j] = std::min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
    // }

    read(q);
    while (q--)
    {
        int l, r, k;
        read(l, r, k);
        int len = lg2[k];
        int res = 0;
        // if (!flag)
            for (int i = l; i + k - 1 <= r; ++i)
                res = std::max(res, dep[lca(st[i][len], st[i + k - (1 << len)][len])]);
        // else {
        //     for(int i=l; i + k - 1 <= r; ++i)
        //         res = std::max(res, std::min(st[i][len], st[i + k - (1 << len)][len]));
        // }

        write(res);
        puts("");
    }

    return 0;
}