#include <bits/stdc++.h>

int main() {
  freopen("query.in", "r", stdin);
  freopen("query.out", "w", stdout);
  int n; scanf("%d", &n);
  std::vector<std::vector<int>> e(n);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d %d", &u, &v), --u, --v;
    e[u].push_back(v), e[v].push_back(u);
  }
  int m = std::log2(n);
  std::vector<int> dep(n), f(n);
  std::vector<std::vector<int>> fa(n, std::vector<int>(m + 1, -1));
  std::function<void(int, int)> dfs = [&](int u, int f) {
    for (int i = 1; i <= m; i++) {
      if (fa[u][i - 1] == -1) break;
      fa[u][i] = fa[fa[u][i - 1]][i - 1];
    }
    for (auto v : e[u]) if (v != f) {
      dep[v] = dep[u] + 1, fa[v][0] = u;
      dfs(v, u);
    }
  };
  dep[0] = 1, dfs(0, -1);
  auto lca = [&](int u, int v) {
    if (dep[u] < dep[v]) std::swap(u, v);
    for (int i = m; i >= 0; i--) if (fa[u][i] != -1 && dep[fa[u][i]] >= dep[v])
      u = fa[u][i];
    if (u == v) return u;
    for (int i = m; i >= 0; i--) if (fa[u][i] != fa[v][i])
      u = fa[u][i], v = fa[v][i];
    return fa[u][0];
  };
  for (int i = 0; i + 1 < n; i++)
    f[i] = dep[lca(i, i + 1)];
  std::vector<std::vector<int>> st(m + 1, std::vector<int>(n)), dst(st);
  st[0] = f, dst[0] = dep;
  for (int i = 1; i <= m; i++)
    for (int j = 0; j + (1 << i) < n; j++) {
      st[i][j] = std::min(st[i - 1][j], st[i - 1][j + (1 << i - 1)]);
      dst[i][j] = std::max(dst[i - 1][j], dst[i - 1][j + (1 << i - 1)]);
    }
  auto qry = [&](int l, int r) {
    int t = std::log2(r - l + 1);
    return std::min(st[t][l], st[t][r - (1 << t) + 1]);
  };
  auto qry2 = [&](int l, int r) {
    int t = std::log2(r - l + 1);
    return std::max(dst[t][l], dst[t][r - (1 << t) + 1]);
  };
  int q; scanf("%d", &q);
  while (q--) {
    int l, r, k; scanf("%d %d %d", &l, &r, &k), --l, --r;
    if (l == r) {
      printf("%d\n", dep[l]);
      continue;
    }
    --k, --r;
    if (!k) {
      printf("%d\n", qry2(l, r + 1));
      continue;
    }
    int ans = 1;
    for (int i = l; i <= r - k + 1; i++) 
      ans = std::max(ans, qry(i, i + k - 1));
    printf("%d\n", ans);
  }
}
// expected point : 32
