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

const int MXN = 500005;
const int MXLG = 19;
int N, Q, dep[MXLG][MXN], mni[MXLG][MXN], mxi[MXLG][MXN], did, lg2[MXN];
vector<int> to[MXN];

int read() {
  int x(0), c(getchar());
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + (c - '0'), c = getchar();
  return x;
}
void write(int x) {
  static char buf[11];
  assert(x);
  int d(0);
  while (x) buf[d++] = x % 10 + '0', x /= 10;
  while (d) putchar(buf[--d]);
}

void dfs(int p, int f) {
  int ci(did);
  mni[0][p] = mxi[0][p] = ++did;
  for (int q : to[p]) if (q != f) dep[0][did] = dep[0][ci] + 1, dfs(q, p);
}

inline pair<int, int> qmnmx(int l, int r) {
  int n(lg2[r - l]);
  return make_pair(min(mni[n][l], mni[n][r - (1 << n)]),
                   max(mxi[n][l], mxi[n][r - (1 << n)]));
}
inline int qdep(pair<int, int> rg) {
  int l(rg.first), r(rg.second);
  if (l == r) return dep[0][l - 1] + 1;
  int n(lg2[r - l]);
  return min(dep[n][l], dep[n][r - (1 << n)]);
}

int main() {
  freopen("query.in", "r", stdin);
  freopen("query.out", "w", stdout);
  N = read();
  for (int i(1), x(0), y(0); i != N; ++i)
    x = read() - 1, y = read() - 1, to[x].push_back(y), to[y].push_back(x);
  dfs(0, -1);
  for (int i(2); i <= N; ++i) lg2[i] = lg2[i >> 1] + 1;
  for (int i(1); (1 << i) <= N; ++i)
    for (int j(0); j + (1 << i) <= N; ++j) {
      dep[i][j] = min(dep[i - 1][j], dep[i - 1][j + (1 << (i - 1))]);
      mni[i][j] = min(mni[i - 1][j], mni[i - 1][j + (1 << (i - 1))]);
      mxi[i][j] = max(mxi[i - 1][j], mxi[i - 1][j + (1 << (i - 1))]);
    }
  Q = read();
  for (int l(0), r(0), k(0); Q--;) {
    l = read() - 1, r = read(), k = read();
    int ans(0);
    for (int i(l); i + k <= r; ++i)
      ans = max(qdep(qmnmx(i, i + k)), ans);
    write(ans), putchar('\n');
  }
  return 0;
}
