#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 100;
vector<int> g[N];
int dfn[N], clk, dep[N], id[N];
int tp[N], ms[N], siz[N], fa[N];
void dfs1(int u, int f){
    fa[u] = f;
    siz[u] = 1;
    dep[u] = dep[f] + 1;
    for(int v : g[u]){
        if(v == f) continue;
        dfs1(v, u);
        siz[u] += siz[v];
        if(!ms[u] || siz[v] < siz[ms[u]]) ms[u] = v;
    }
}
void dfs2(int u, int top){
    dfn[u] = ++clk;
    id[clk] = u;
    tp[u] = top;
    if(ms[u]) dfs2(ms[u], top);
    for(int v : g[u]){
        if(v == ms[u] || v == fa[u]) continue;
        dfs2(v, v);
    }
}
int n, Lg[N];
int Mn[N][20], Mx[N][20];
int cmp1(int x, int y){
    return dfn[x] < dfn[y] ? x : y;
}
int cmp2(int x, int y){
    return dfn[x] > dfn[y] ? x : y;
}
void st_init(){
    Lg[1] = 0;
    for(int i = 2;i <= n;i++) Lg[i] = Lg[i / 2] + 1;
    for(int i = 1;i <= n;i++) Mn[i][0] = Mx[i][0] = i;
    for(int j = 1;j <= 19;j++){
        for(int i = 1;i + (1 << (j - 1)) <= n;i++){
            Mn[i][j] = cmp1(Mn[i][j - 1], Mn[i + (1 << (j - 1))][j - 1]);
            Mx[i][j] = cmp2(Mx[i][j - 1], Mx[i + (1 << (j - 1))][j - 1]);
        }
    }
}
pair<int, int> gt(int x, int y){
    int k = Lg[y - x + 1];
    return {cmp1(Mn[x][k], Mn[y - (1 << k) + 1][k]), cmp2(Mx[x][k], Mx[y - (1 << k) + 1][k])};
}
int get_lca(int x, int y){
    if(x == y) return x;
    while(tp[x] != tp[y]){
        if(dep[tp[x]] < dep[tp[y]]) swap(x, y);
        x = fa[tp[x]];
    }
    return dep[x] < dep[y] ? x : y;
 }
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;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs1(1, 0);
    dfs2(1, 1);
    st_init();
    int _q;cin >>_q;
    while(_q--){
        int l, r, k, ans = 0;
        cin >> l >> r >> k;
        if(k == r - l + 1){
            pair<int, int> pt = gt(l, r);
            cout << dep[get_lca(pt.first, pt.second)] << endl;
            continue;
        }
        for(int i = l, j = l + k - 1;j <= r;i++, j++){
            pair<int, int> cur = gt(i, j);
            int lca = get_lca(cur.first, cur.second);
            ans = max(ans, dep[lca]);
        }
        cout << ans << endl;
    }
    return 0;
}