#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

const int MAXN = 5000; //...
const int BITS = 13;

int n;
std::vector<int> graph[MAXN+3];
int depth[MAXN+3];
int fa[MAXN+3][BITS+1];

void dfs(int x, int fa_, int depth_) {
    fa[x][0] = fa_;
    depth[x] = depth_;

    for (int y: graph[x]) {
        if (y == fa_) continue;
        dfs(y, x, depth_ + 1);
    }
}

void init_st() {
    for (int i = 1; i <= BITS; i++) { //?
        for (int x = 0; x < n; x++) {
            fa[x][i] = fa[fa[x][i-1]][i-1];
        }
    }
}

void init() {
    dfs(0, 0, 1);
    init_st();
}

int get_lca(int x, int y) {
    if (depth[x] < depth[y])
        std::swap(x, y);
    int delta = depth[x] - depth[y];
    for (int i = BITS; i >= 0; i--) { //?
        if (delta & (1<<i)) {
            x = fa[x][i];
        }
    }
    if (x == y) {
//        return fa[x][0];
//std::cerr << "#1 " <<x;
        return x;}
//    int dep = depth[x];
//std::cerr << "#1 " <<x << ' ' << dep << '\n';
    for (int i = BITS; i >= 0; i--) {
//        if (dep & (1<<i)) {
            //?
            if (fa[x][i] != fa[y][i]) {
                x = fa[x][i];
                y = fa[y][i];
            }
//        }
    }
//std::cerr << "#2 " <<x << '\n';
    return fa[x][0];
}

int query(int l_, int r, int k) {
//    std::cerr << "* " << l_ << ' ' << r << ' ' <<k <<'\n';
    int res = 0;
    for (int l = l_; l + k - 1 <= r; l++) { // [l, l+k) = [l, l+k-1]
        // Compute dep_{LCA*(l, l+k)}
        int lca = l;
        for (int i = l + 1; i <= l + k - 1; i++) {
            lca = get_lca(lca, i);
            if (depth[lca] <= res) goto skip;
        }
//        std::cerr << l << ' ' << lca <<' ' << depth[lca] << '\n';
        res = std::max(res, depth[lca]);
        skip:;
    }
    return res;
}

int main() {
#ifdef LOCAL_
    std::ifstream fin("data/query/query2.in");
    auto&& fout = std::cout;
#else
    std::ifstream fin("query.in");
    std::ofstream fout("query.out");
#endif // LOCAL_

    fin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        fin >> u >> v;
        u--;
        v--;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    init();
//    std::cerr << get_lca(3, 4);
//    return 0;
    int q;
    fin >> q;
    for (; q > 0; q--) {
        int l, r, k;
        fin >> l >> r >> k;
        l--;
        r--;
        fout << query(l, r, k) << '\n';
    }
    return 0;
}
































