#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <queue>
#include <set>
#include <utility>
#include <random>
#define fi first
#define se second
using namespace std;
typedef long long LL;

template <typename Tp> inline void read(Tp& x) {
    char ch; bool op = 0; x = 0;
    do ch = getchar(), op |= ch == '-'; while (ch < '0' || ch > '9');
    do x = (x<<3)+(x<<1)+(ch&15), ch = getchar(); while (ch >= '0' && ch <= '9');
    if (op) x = -x;
}

template <typename Tp> inline void write(Tp x, char ed='\n') {
    static int arr[50]; int tp = 0;
    if (x < 0) putchar('-'), x = -x;
    do arr[++tp] = x % 10, x /= 10; while (x);
    for (; tp; --tp) putchar(arr[tp] | 48);
    putchar(ed);
}

const int mod = 1e9+7;
inline int fplus(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
inline int Fplus(int& x, int y) { return x = fplus(x, y); }
inline int fminus(int x, int y) { return x - y < 0 ? x - y + mod : x - y; }
inline int Fminus(int& x, int y) { return x = fminus(x, y); }

bool Mst;

const int MAXN = 5e5+5;
int n, m;
int head[MAXN], ver[MAXN<<1], nxt[MAXN<<1], tot;
int dep[MAXN], pa[MAXN], eln[MAXN<<1], be[MAXN], ed[MAXN], cnt;

void add(int x, int y) {
    ver[++tot] = y, nxt[tot] = head[x], head[x] = tot;
}

namespace ST {
    int f[20][MAXN<<1], lg[MAXN<<1];
    void init() {
        lg[0] = -1;
        for (int i = 1; i <= cnt; ++i) f[0][i] = dep[eln[i]], lg[i] = lg[i>>1] + 1;
        for (int k = 0; k < 19; ++k) {
            int len = 1<<k;
            for (int i = 1; i <= cnt-(len<<1)+1; ++i) {
                f[k+1][i] = min(f[k][i], f[k][i+len]);
            }
        }
    }
    int query(int l, int r) {
        int k = lg[r-l+1], len = 1<<k;
        return min(f[k][l], f[k][r-len+1]);
    }
}

void dfs(int x) {
    dep[x] = dep[pa[x]] + 1, eln[++cnt] = x, be[x] = ed[x] = cnt;
    for (int i = head[x]; i; i = nxt[i]) {
        int y = ver[i];
        if (y == pa[x]) continue;
        pa[y] = x;
        dfs(y);
        eln[++cnt] = x;
        ed[x] = cnt;
    }
}

int solve(int l, int r, int k) {
    set<int> pos;
    for (int i = l; i <= l + k - 1; ++i) pos.insert(be[i]);
    int ans = ST::query(*pos.begin(), *--pos.end());
    for (int i = l; i <= r - k; ++i) {
        pos.erase(be[i]), pos.insert(be[i+k]);
        ans = max(ans, ST::query(*pos.begin(), *--pos.end()));
    }
    return ans;
}

bool Med;

int main() {
    freopen("query.in", "r", stdin);
    freopen("query.out", "w", stdout);
    fprintf(stderr, "%.3lf\n", (&Mst - &Med) / 1048576.);
    read(n);
    for (int i = 1; i < n; ++i) {
        int x, y; read(x), read(y); add(x, y), add(y, x);
    }
    dfs(1);
    ST::init();
    read(m);
    while (m--) {
        int l, r, k;
        read(l), read(r), read(k);
        write(solve(l, r, k));
    }
    return 0;
}

