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

using ll = long long;
using ull = unsigned long long;
using ldb = long double;
using ui = unsigned int;

#define mp make_pair
#define eb emplace_back
#define fi first
#define se second

#ifdef _DEBUG
#define dbg(...) __VA_ARGS__
#else
#define dbg(...) void();
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int radint(int l, int r) {
  return uniform_int_distribution<>(l, r)(rng);
}

const int N = 5e5 + 5;
struct Graph {
  int head[N], nxt[N * 2], to[N * 2], tot;
  void add(int u, int v) {
    nxt[++tot] = head[u];
    to[tot] = v;
    head[u] = tot;
  }
} G;

int fa[N], dep[N], dfn[N], dfn_cnt, lg2[N];
pair<int, int> st[N][19];
void dfs(int x) {
  dep[x] = dep[fa[x]] + 1;
  dfn[x] = ++dfn_cnt;
  st[dfn_cnt][0] = mp(dep[x], x);
  for (int i = G.head[x]; i; i = G.nxt[i]) {
    if (G.to[i] == fa[x]) continue;
    fa[G.to[i]] = x;
    dfs(G.to[i]);
  }
}
int qry(int l, int r) {
  int k = lg2[r - l + 1];
  return min(st[l][k], st[r - (1 << k) + 1][k]).second;
}
int lca(int x, int y) {
  if (x == y) return x;
  if (dfn[x] > dfn[y]) swap(x, y);
  return fa[qry(dfn[x] + 1, dfn[y])];
}
int l[N][19];
int qry2(int x, int y) {
  int k = lg2[y - x + 1];
  return lca(l[x][k], l[y - (1 << k) + 1][k]);
}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  freopen("query.in", "r", stdin);
  freopen("query.out", "w", stdout);
  int n;
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    G.add(u, v);
    G.add(v, u);
  }
  dfs(1);
  for (int i = 2; i <= n; ++i) lg2[i] = lg2[i / 2] + 1;
  for (int i = 1; i < 19; ++i) {
    for (int j = 1; j <= n - (1 << i) + 1; ++j) {
      st[j][i] = min(st[j][i - 1], st[j + (1 << (i - 1))][i - 1]);
    }
  }
  for (int i = 1; i <= n; ++i) l[i][0] = i;
  for (int i = 1; i < 19; ++i) {
    for (int j = 1; j <= n - (1 << i) + 1; ++j) {
      l[j][i] = lca(l[j][i - 1], l[j + (1 << (i - 1))][i - 1]);
    }
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    int l, r, k;
    cin >> l >> r >> k;
    int ans = 0;
    for (int j = l; j + k - 1 <= r; ++j) {
      ans = max(ans, dep[qry2(j, j + k - 1)]);
    }
    cout << ans << '\n';
  }
  return 0;
}