#include <bits/stdc++.h>
using namespace std;
vector<int> pos(24);
vector<vector<int> > matrix;
int search(int GG) {
  int l = 0, r = 19;
  for (int m = (l + r) / 2; l != r; m = (l + r) / 2) {
    if (pos[m] <= GG)
      l = m + 1;
    else
      r = m;
  }
  return l;
}
int RMQ(int x, int y, vector<vector<int> >& RMQQ) {
  int dis = y - x + 1;
  int l = 0, r = 19;
  for (int m = (l + r) / 2; l != r; m = (l + r) / 2) {
    if (pos[m] <= dis)
      l = m + 1;
    else
      r = m;
  }
  return max(RMQQ[l - 1][x], RMQQ[l - 1][y - pos[l - 1] + 1]);
}
int maxxx(int A, int B) {
  if (A > B) return A;
  return B;
}
void init_RMQ(vector<int>& K, vector<vector<int> >& RMQQ) {
  int N = K.size();
  pos[0] = 1;
  for (int I = 1; I < 24; I++) {
    pos[I] = pos[I - 1] * 2;
  }
  int pot2 = search(N);
  RMQQ.resize(pot2 + 1, vector<int>(N));
  for (int I = 0; I < N; I++) {
    RMQQ[0][I] = K[I];
  }
  for (int I = 1; I <= pot2; I++) {
    for (int I2 = 0; I2 < N; I2++) {
      if (pos[I - 1] + I2 < N) {
        RMQQ[I][I2] = maxxx(RMQQ[I - 1][I2], RMQQ[I - 1][I2 + pos[I - 1]]);
      } else
        RMQQ[I][I2] = RMQQ[I - 1][I2];
    }
  }
}
int bfs(int nodo) {
  pair<int, int> PAR;
  queue<pair<int, int> > COLA;
  COLA.push(make_pair(nodo, -1));
  while (!COLA.empty()) {
    PAR = COLA.front();
    COLA.pop();
    for (int I = 0; I < matrix[PAR.first].size(); I++) {
      if (matrix[PAR.first][I] != PAR.second) {
        COLA.push(make_pair(matrix[PAR.first][I], PAR.first));
      }
    }
    if (COLA.empty()) return PAR.first;
  }
}
bool ss(int A, int B, vector<int>& Diametro, int i) {
  if (A == B) {
    Diametro.push_back(B);
    return true;
  }
  for (int I = 0; I < matrix[A].size(); I++) {
    if (matrix[A][I] != i) {
      if (ss(matrix[A][I], B, Diametro, A)) {
        Diametro.push_back(A);
        return true;
      }
    }
  }
  return false;
}
vector<int> Pertenencia;
void dfs(int A, vector<int>& Gu, int i, int pert, vector<int>& isD, int dist,
         vector<int>& Dists) {
  if (isD[A] != -1) {
    pert = isD[A];
  }
  Dists[A] = dist;
  Gu[pert] = max(Gu[pert], dist);
  Pertenencia[A] = pert;
  for (int I = 0; I < matrix[A].size(); I++) {
    if (matrix[A][I] != i) {
      dfs(matrix[A][I], Gu, A, pert, isD, dist + 1, Dists);
    }
  }
}
int main() {
  int N, A, B, Q, Lado1, Lado2;
  scanf("%d", &N);
  matrix.resize(N);
  for (int I = 0; I < N - 1; I++) {
    scanf("%d%d", &A, &B);
    A--;
    B--;
    matrix[A].push_back(B);
    matrix[B].push_back(A);
  }
  Lado1 = bfs(0);
  Lado2 = bfs(Lado1);
  vector<int> Diametro;
  bool charmander = ss(Lado2, Lado1, Diametro, -1);
  vector<int> isD(N, -1);
  for (int I = 0; I < Diametro.size(); I++) {
    isD[Diametro[I]] = I;
  }
  vector<int> G1(Diametro.size()), G2(Diametro.size());
  vector<int> Dists1(N, 0), Dists2(N, 0);
  Pertenencia.resize(N);
  dfs(Lado1, G1, -1, -1, isD, 0, Dists1);
  dfs(Lado2, G2, -1, -1, isD, 0, Dists2);
  scanf("%d", &Q);
  int si = Diametro.size();
  vector<vector<int> > RMQ1, RMQ2;
  init_RMQ(G1, RMQ1);
  init_RMQ(G2, RMQ2);
  si--;
  while (Q--) {
    scanf("%d%d", &A, &B);
    A--;
    B--;
    if (Pertenencia[A] == Pertenencia[B]) {
      if (Dists1[A] > Dists1[B]) {
        A = B;
      }
      printf("%d\n", max(Dists1[A], Dists2[A]));
    } else {
      if (Pertenencia[A] < Pertenencia[B]) {
        int J = B;
        B = A;
        A = J;
      }
      int maxi = 0;
      int DA = Dists1[A] - Pertenencia[A];
      int DB = Dists1[B] - Pertenencia[B];
      int PB = Pertenencia[B] + DA - DB;
      int hasta = (PB + Pertenencia[A]) / 2;
      if (hasta > Pertenencia[B]) {
        if (hasta >= Pertenencia[A]) hasta = si;
        maxi = max(Dists1[B], RMQ(Pertenencia[B] + 1, hasta, RMQ1) + Dists1[B] -
                                  Pertenencia[B] - Pertenencia[B]);
      } else if (hasta == Pertenencia[B])
        maxi = max(maxi, Dists1[B]);
      if (hasta + 1 < Pertenencia[A]) {
        if (hasta + 1 <= Pertenencia[B]) hasta = -1;
        if (hasta + 1 < 0) hasta = -1;
        maxi = max(maxi, RMQ(hasta + 1, Pertenencia[A] - 1, RMQ2) + Dists2[A] -
                             (si - Pertenencia[A]) - (si - Pertenencia[A]));
        maxi = max(maxi, Dists2[A]);
      } else if (hasta + 1 == Pertenencia[A]) {
        maxi = max(maxi, Dists2[A]);
      }
      printf("%d\n", maxi);
    }
  }
  return 0;
}
