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

const int N = 1e6 + 5;
pair<int, int> st[20][N], st2[20][N], st3[20][N];
int lg[N];

int main() {
  freopen("query.in", "r", stdin);
  freopen("query.out", "w", stdout);
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> g(n);
  vector<int> d(n), dep(n), dfn(n);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].emplace_back(v), g[v].emplace_back(u);
    d[u]++, d[v]++;
  }
  int sts = 0;
  auto dfs = [&](auto&& dfs, int x, int fa) -> void {
    dfn[x] = sts;
    st[0][sts++] = {dep[x], x};
    for (auto to : g[x]) {
      if (to != fa) {
        dep[to] = dep[x] + 1;
        dfs(dfs, to, x);
        st[0][sts++] = {dep[x], x};
      }
    }
  };
  dfs(dfs, 0, -1);
  for (int i = 0; i < n; i++) st2[0][i] = {dfn[i], i}, st3[0][i] = {dfn[i], i};
  lg[1] = 0;
  for (int i = 2; i < N; i++) lg[i] = lg[i / 2] + 1;
  for (int i = 1; i < 20; i++)
    for (int j = 0; j + (1 << i) - 1 < sts; j++) {
      st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << i - 1)]);
    }
  for (int i = 1; i < 20; i++)
    for (int j = 0; j + (1 << i) - 1 < n; j++) {
      st2[i][j] = min(st2[i - 1][j], st2[i - 1][j + (1 << i - 1)]),
      st3[i][j] = max(st3[i - 1][j], st3[i - 1][j + (1 << i - 1)]);
    }
  auto LCA = [&](int x, int y) {
    x = dfn[x], y = dfn[y];
    if (x > y) swap(x, y);
    int dif = y - x + 1;
    int c = lg[dif];
    return min(st[c][x], st[c][y - (1 << c) + 1]);
  };
  auto LCA2 = [&](int l, int r) {
    int dif = r - l + 1;
    int c = lg[dif];
    auto res1 = min(st2[c][l], st2[c][r - (1 << c) + 1]).second;
    auto res2 = max(st3[c][l], st3[c][r - (1 << c) + 1]).second;
    return LCA(res1, res2);
  };
  int q;
  cin >> q;
  while (q--) {
    int l, r, k;
    cin >> l >> r >> k;
    --l, --r;
    if (k == r - l + 1) {
      cout << LCA2(l, r).first + 1 << '\n';
    } else if (n <= 10000 && q <= 10000) {
      int res = 0;
      for (int L = l; L + k - 1 <= r; L++) {
        res = max(res, LCA2(L, L + k - 1).first);
      }
      cout << res + 1 << '\n';
    } else {
    }
  }
}

/*
整体二分假完了
*/
