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

const int N = 5e5 + 505;

int logs[N];
int dep[N], fa[N][31];
int maxl[N][31];

int n;
vector<int> e[N];

void dfs(int x, int fath) {
    fa[x][0] = fath;
    dep[x] = dep[fath] + 1;
    for(int v : e[x]) {
        if(v == fath) continue;
        dfs(v, x);
    }
    return;
}

void fainit() {
    for(int i = 2; i <= n; i++)
        logs[i] = logs[i >> 1] + 1;
    for(int j = 1; j <= 30; j++) {
        for(int i = 1; i <= n; i++) {
            fa[i][j] = fa[fa[i][j - 1]][j - 1];
        }
    }
    return;
}
int glca(int x, int y) {
    if(!x || !y) return x ^ y;
    if(dep[x] < dep[y]) swap(x, y);
    for(int j = 30; j >= 0; j--)
        if(dep[fa[x][j]] >= dep[y])
            x = fa[x][j];
    if(x == y) return x;
    for(int j = 30; j >= 0; j--) {
        if(fa[x][j] != fa[y][j])
            x = fa[x][j], y = fa[y][j];
    }
    return fa[x][0];
}
void init() {
    for(int i = 1; i <= n; i++)
        maxl[i][0] = i;
    for(int j = 1; j <= 30; j++) {
        for(int i = 1; i + (1 << (j - 1)) <= n; i++) {
            maxl[i][j] = glca(maxl[i][j - 1], maxl[i + (1 << (j - 1))][j - 1]);
        }
    }
    return;
}
int gmaxlca(int l, int r) {
    int s = logs[r - l + 1];
    return glca(maxl[l][s], maxl[r - (1 << s) + 1][s]);
}
int q;

int main() {
    freopen("query.in", "r", stdin);
    freopen("query.out", "w", stdout);
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1; i < n; i++) {
        int x, y;
        cin >> x >> y;
        e[x].push_back(y), e[y].push_back(x);
    }
    dfs(1, 0);
    fainit();
    init();
    cin >> q;
    for(int i = 1; i <= q; i++) {
        int l, r, k;
        cin >> l >> r >> k;
        int ans = dep[gmaxlca(l, l + k - 1)];
        for(int j = l + 1; j + k - 1 <= r; j++) {
            ans = max(dep[gmaxlca(j, j + k - 1)], ans);
        }
        cout << ans << '\n';
    }
    return 0;
}