#include <bits/stdc++.h>
using namespace std;
const int C = 100001;
vector<vector<int> > tr(C);
int ij[C], a, b, n, q;
int s[C], is = 0, ip = 1, pre[C], apre[C], dep[C], son[C], par[21][C], ji[C],
          d[4][C], lst[4][C], mx[21][C], mx2[21][C];
int anc(int a, int b) {
  if (pre[a] <= pre[b] && pre[a] + son[a] > pre[b]) return 1;
  return 0;
}
void e2(int x, int p1, int p2) { d[p2][x] = d[p1][x], lst[p2][x] = lst[p1][x]; }
void exch(int s, int p) {
  if (d[0][s] == 0) lst[0][s] = s;
  if (d[0][s] + 1 > d[0][p])
    e2(p, 1, 2), e2(p, 0, 1), d[0][p] = d[0][s] + 1, lst[0][p] = lst[0][s];
  else if (d[0][s] + 1 > d[1][p])
    e2(p, 1, 2), d[1][p] = d[0][s] + 1, lst[1][p] = lst[0][s];
  else if (d[0][s] + 1 > d[2][p])
    d[2][p] = d[0][s] + 1, lst[2][p] = lst[0][s];
}
void proc_tree(int a, int n, vector<vector<int> > &tab, int ij[]) {
  s[0] = a, is = 1, pre[a] = 1, apre[1] = a, dep[a] = 1, ip = 2;
  int b, z;
  d[3][a] = 0, lst[3][a] = a;
  for (z = 1; z <= n; z++) ji[z] = ij[z];
  while (is > 0) {
    a = s[is - 1];
    if (ji[a] > 0 && tab[a][ji[a] - 1] == par[0][a]) ji[a]--;
    if (ji[a] > 0)
      b = s[is] = tab[a][ji[a] - 1], pre[b] = ip, apre[ip] = b, par[0][b] = a,
      dep[b] = is + 1, ip++, is++, ji[a]--;
    else
      son[a]++, son[par[0][a]] += son[a], exch(a, par[0][a]),
          mx[0][a] = d[1][a] - dep[a], mx2[0][a] = d[1][a] + dep[a], is--;
  }
  for (z = 2; z <= n; z++) {
    b = apre[z], a = par[0][b];
    if (anc(b, lst[0][a]) == 0)
      d[3][b] = d[0][a] + 1, lst[3][b] = lst[0][a];
    else if (lst[1][a] != 0)
      d[3][b] = d[1][a] + 1, lst[3][b] = lst[1][a];
    if (d[3][b] < d[3][a] + 1) d[3][b] = d[3][a] + 1, lst[3][b] = lst[3][a];
  }
}
void prep_lca(int f, int n) {
  par[0][1] = 1;
  for (int j = 1; j < f; j++) {
    for (int i = 1; i <= n; i++) {
      par[j][i] = par[j - 1][par[j - 1][i]];
      mx[j][i] = max(mx[j - 1][i], mx[j - 1][par[j - 1][i]]);
      mx2[j][i] = max(mx2[j - 1][i], mx2[j - 1][par[j - 1][i]]);
    }
  }
}
int kth_anc(int a, int k) {
  int i = 0;
  while (k > 0) {
    if (k % 2 == 1) a = par[i][a];
    k /= 2, i++;
  }
  return a;
}
int lca(int a, int b, int f = 17) {
  if (anc(a, b) == 1) return a;
  if (anc(b, a) == 1) return b;
  int i = f, x = a;
  while (i >= 0) {
    if (anc(par[i][x], b) == 1)
      i--;
    else
      x = par[i][x];
  }
  return par[0][x];
}
int f(int a, int b) {
  int i = 17, x = a, wynn = -1000000;
  if (anc(a, b) == 1) return wynn;
  while (i >= 0) {
    if (anc(par[i][x], b) == 1)
      i--;
    else
      wynn = max(mx[i][x], wynn), x = par[i][x];
  }
  return max(wynn, mx[0][x]);
}
int g(int a, int b) {
  int i = 17, x = a, wynn = -1000000;
  if (anc(a, b) == 1) return wynn;
  while (i >= 0) {
    if (anc(par[i][x], b) == 1)
      i--;
    else
      wynn = max(mx2[i][x], wynn), x = par[i][x];
  }
  return max(wynn, mx2[0][x]);
}
int main() {
  int i, j, x, ds, sr, f1, f2, f3, f4, Mxd = 0, p1, p2;
  scanf("%d", &n);
  for (int z = 1; z < n; z++)
    scanf("%d %d", &a, &b), tr[a].push_back(b), tr[b].push_back(a), ij[a]++,
        ij[b]++;
  proc_tree(1, n, tr, ij);
  prep_lca(18, n);
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d", &a, &b);
    if (dep[a] < dep[b]) a = a + b, b = a - b, a = a - b;
    x = lca(a, b);
    p1 = kth_anc(a, dep[a] - dep[x] - 1);
    p2 = kth_anc(b, dep[b] - dep[x] - 1);
    ds = dep[a] + dep[b] - 2 * dep[x];
    sr = kth_anc(a, ds / 2 + ds % 2 - 1);
    f1 = lca(lst[0][sr], a);
    Mxd = max(f(f1, par[0][sr]) + dep[a], d[0][f1] + dep[a] - dep[f1]);
    if (b != x) {
      f1 = lca(lst[0][p2], b);
      Mxd = max(f(f1, x) + dep[b], Mxd);
      Mxd = max(d[0][f1] + dep[b] - dep[f1], Mxd);
    } else {
      if (anc(p1, lst[0][x]) == 0)
        Mxd = max(d[0][x], Mxd);
      else
        Mxd = max(d[1][x], Mxd);
    }
    f1 = lca(lst[0][p1], a);
    if (anc(sr, f1) == 0)
      Mxd = max(Mxd, d[0][f1] + dep[b] - 2 * dep[x] + dep[f1]);
    Mxd = max(Mxd, g(par[0][sr], x) + dep[b] - 2 * dep[x]);
    Mxd = max(dep[b] - dep[x] + d[3][x], Mxd);
    if (anc(p1, lst[0][x]) == 0 && anc(p2, lst[0][x]) == 0)
      Mxd = max(dep[b] - dep[x] + d[0][x], Mxd);
    else if (anc(p1, lst[1][x]) == 0 && anc(p2, lst[1][x]) == 0)
      Mxd = max(dep[b] - dep[x] + d[1][x], Mxd);
    else
      Mxd = max(dep[b] - dep[x] + d[2][x], Mxd);
    printf("%d\n", Mxd);
    Mxd = 0;
  }
  return 0;
}
