#include <bits/stdc++.h>
#define IL inline
#define LL long long
#define eb emplace_back
#define sz(v) ((int) (v).size())
#define me(f, x) memset(f, x, sizeof(f))
#define mc(f, g) memcpy(f, g, sizeof(f))
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
using namespace std;

using vi = vector<int>;

bool Mbe;

constexpr int N = 5e5 + 9;
int n, q;
int dfn[N], sq[N], dfc, st[20][N], dep[N];
vi g[N];

void dfs (int u, int f) {
  dfn[u] = ++dfc;
  sq[dfc] = u;
  st[0][dfc] = f;
  dep[u] = dep[f] + 1;
  for (int v : g[u]) {
    if (v ^ f) {
      dfs(v, u);
    }
  }
}

IL int cp (int x, int y) {
  return dfn[x] < dfn[y] ? x : y;
}

IL int lca (int x, int y) {
  if (x == y) {
    return x;
  }
  if ((x = dfn[x]) > (y = dfn[y])) {
    swap(x, y);
  }
  int i = 31 ^ __builtin_clz(y - x++);
  return cp(st[i][x], st[i][y - (1 << i) + 1]);
}

struct tab {
  function<int(int, int)> cmp;
  int f[20][N];

  void init () {
    L (i, 1, 19) {
      L (j, 1, n - (1 << i) + 1) {
        f[i][j] = cmp(f[i - 1][j], f[i - 1][j + (1 << (i - 1))]);
      }
    }
  }

  int q (int l, int r) {
    int i = 31 ^ __builtin_clz(r - l + 1);
    return cmp(f[i][l], f[i][r - (1 << i) + 1]);
  }
} A, B;

namespace F {

bool fl;
int sq[N], dfc;

void dfs (int u, int f) {
  int cnt = 0;
  sq[++dfc] = u;
  for (int v : g[u]) {
    if (v ^ f) {
      dfs(v, u);
      ++cnt;
    }
  } 
  if (cnt > 1) {
    fl = 0;
  }
}

struct V {
  int s, l, r, x;
};

IL V merge (V a, V b) {
  V c;
  c.s = a.s + b.s;
  c.l = max(a.l, a.s + b.l);
  c.r = max(b.r, b.s + a.r);
  c.x = max({a.x, b.x, a.r + b.l});
  return c;
}

int rt[N], tot;
struct nd {
  V x;
  int ch[2];
} t[N << 5];

#define ls(p) t[p].ch[0]
#define rs(p) t[p].ch[1]

void ins (int x, int l, int r, int p, int &q) {
  t[q = ++tot] = t[p];
  if (l == r) {
    t[q].x = {1, 1, 1, 1};
    return;
  }
  int md = (l + r) >> 1;
  x <= md ? ins(x, l, md, ls(p), ls(q)) : ins(x, md + 1, r, rs(p), rs(q));
  t[q].x = merge(t[ls(q)].x, t[rs(q)].x);
}

V qry (int ql, int qr, int l, int r, int p) {
  if (!p) {
    return (V){0, 0, 0, 0};
  }
  if (ql <= l && r <= qr) {
    return t[p].x;
  }
  int md = (l + r) >> 1;
  if (qr <= md) {
    return qry(ql, qr, l, md, ls(p));
  }
  if (md < ql) {
    return qry(ql, qr, md + 1, r, rs(p));
  }
  return merge(qry(ql, qr, l, md, ls(p)), qry(ql, qr, md + 1, r, rs(p)));
}

void main () {
  dfc = 0;
  fl = 1;
  dfs(1, 0);
  if (!fl) {
    return;
  }
  R (i, n, 1) {
    ins(sq[i], 1, n, rt[i + 1], rt[i]);
  }
  cin >> q;
  while (q--) {
    int l, r, k;
    cin >> l >> r >> k;
    int L = 1, R = n;
    while (L < R) {
      int M = (L + R + 1) >> 1;
      qry(l, r, 1, n, rt[M]).x >= k ? L = M : R = M - 1;
    }
    cout << L << '\n';
  }
  tot = 0;
  L (i, 1, n) {
    rt[i] = 0;
  }
  exit(0);
}

}

bool Med;

int main () {
  // cerr << (&Mbe - &Med) / 1048576. << '\n';
  // return 0;
  FIO("query");
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  L (i, 1, n - 1) {
    int u, v;
    cin >> u >> v;
    g[u].eb(v);
    g[v].eb(u);
  }
  F::main();
  dfs(1, 0);
  A.cmp = [&] (int x, int y) -> int {
    return dfn[x] < dfn[y] ? x : y;
  };
  B.cmp = [&] (int x, int y) -> int {
    return dfn[x] > dfn[y] ? x : y;
  };
  L (i, 1, n) {
    A.f[0][i] = B.f[0][i] = i;
  }
  A.init();
  B.init();
  L (i, 1, 19) {
    L (j, 1, n - (1 << i) + 1) {
      st[i][j] = cp(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
    }
  }
  cin >> q;
  while (q--) {
    int l, r, k;
    cin >> l >> r >> k;
    int ans = 0;
    L (i, l, r - k + 1) {
      int mn = A.q(i, i + k - 1);
      int mx = B.q(i, i + k - 1);
      ans = max(ans, dep[lca(mn, mx)]);
    }
    cout << ans << '\n';
  }
}
// I love WHQ!