#include <bits/stdc++.h>
using namespace std;
const int maxn = 200001, maxm = 400001;
int n, m;
int h[maxn], t[maxm], ne[maxm];
int dfn[maxn];
int fa[maxn], anc[maxn][30], dep[maxn], uf[maxn], df1[maxn], df2[maxn],
    df3[maxn], ancfd[maxn][30], ancfu[maxn][30];
void dfs(int x) {
  dfn[++dfn[0]] = x;
  for (int i = h[x]; i; i = ne[i])
    if (t[i] != fa[x]) {
      fa[t[i]] = x;
      dfs(t[i]);
    }
}
int Anc(int x, int t) {
  for (int i = 0; i < 30; ++i)
    if (t >> i & 1) x = anc[x][i];
  return x;
}
int Ancfd(int x, int t) {
  if (t < 0) return 0;
  int ans = 0;
  for (int i = 0, j = 0; i < 30; ++i)
    if (t >> i & 1) {
      ans = max(ans, j + ancfd[x][i]);
      j += (1 << i);
      x = anc[x][i];
    }
  return ans;
}
int Ancfu(int x, int t) {
  if (t < 0) return 0;
  int ans = 0;
  for (int i = 0, j = 0; i < 30; ++i)
    if (t >> i & 1) {
      ans = max(ans, t - (1 << i) + ancfu[x][i]);
      t -= (1 << i);
      x = anc[x][i];
    }
  return ans;
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 29; i >= 0; --i)
    if (dep[x] - dep[y] >= (1 << i)) x = anc[x][i];
  if (x == y) return x;
  for (int i = 29; i >= 0; --i)
    if (anc[x][i] != anc[y][i]) {
      x = anc[x][i];
      y = anc[y][i];
    }
  return fa[x];
}
void initialize() {
  dfs(1);
  for (int i = 1; i <= n; ++i) anc[i][0] = fa[i];
  for (int i = 1; i < 30; ++i)
    for (int I = 1, j = dfn[I]; I <= n; ++I, j = dfn[I])
      anc[j][i] = anc[anc[j][i - 1]][i - 1];
  for (int I = 1, i = dfn[I]; I <= n; ++I, i = dfn[I]) dep[i] = dep[fa[i]] + 1;
  for (int I = n, i = dfn[I]; I > 0; --I, i = dfn[I]) {
    df1[i] = df2[i] = df3[i] = -1;
    for (int j = h[i]; j; j = ne[j])
      if (t[j] != fa[i])
        if (df1[t[j]] > df1[i]) {
          df3[i] = df2[i];
          df2[i] = df1[i];
          df1[i] = df1[t[j]];
        } else if (df1[t[j]] > df2[i]) {
          df3[i] = df2[i];
          df2[i] = df1[t[j]];
        } else if (df1[t[j]] > df3[i]) {
          df3[i] = df1[t[j]];
        }
    ++df1[i];
    ++df2[i];
    ++df3[i];
  }
  uf[1] = 0;
  for (int I = 1, i = dfn[I]; I <= n; ++I, i = dfn[I]) {
    for (int j = h[i]; j; j = ne[j])
      if (t[j] != fa[i])
        if (df1[t[j]] + 1 == df1[i]) {
          uf[t[j]] = 1 + max(uf[i], df2[i]);
          ancfd[t[j]][0] = 1 + df2[i];
          ancfu[t[j]][0] = df2[i];
        } else {
          uf[t[j]] = 1 + max(uf[i], df1[i]);
          ancfd[t[j]][0] = 1 + df1[i];
          ancfu[t[j]][0] = df1[i];
        }
  }
  for (int i = 1; i < 30; ++i)
    for (int I = 1, j = dfn[I]; I <= n; ++I, j = dfn[I]) {
      ancfd[j][i] =
          max(ancfd[j][i - 1], (1 << (i - 1)) + ancfd[anc[j][i - 1]][i - 1]);
      ancfu[j][i] =
          max(ancfu[j][i - 1] + (1 << (i - 1)), ancfu[anc[j][i - 1]][i - 1]);
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    ne[i] = h[x];
    h[x] = i;
    t[i] = y;
    ne[i + n] = h[y];
    h[y] = i + n;
    t[i + n] = x;
  }
  initialize();
  for (scanf("%d", &m); m > 0; --m) {
    int A, B;
    scanf("%d%d", &A, &B);
    if (A == 4 && B == 15) {
      ++A;
      --A;
    }
    int F = lca(A, B);
    if (dep[A] < dep[B]) swap(A, B);
    int d = (-dep[F] * 2 + dep[A] + dep[B]) / 2;
    int M = Anc(A, d);
    int ans = df1[A];
    if (B != F) ans = max(ans, df1[B]);
    if (F == M) {
      ans = max(ans, max(Ancfd(A, d - 1), Ancfd(B, d - 1)));
      int AF = Anc(A, dep[A] - dep[F] - 1), BF = Anc(B, dep[B] - dep[F] - 1);
      if (B == F)
        if (df1[AF] + 1 == df1[B])
          ans = max(ans, max(df2[F], uf[F]));
        else
          ans = max(ans, max(df1[F], uf[F]));
      else {
        int t;
        if (df1[AF] + 1 == df1[F] || df1[BF] + 1 == df1[F])
          if ((df1[AF] + 1 == df1[F] && df1[BF] + 1 == df2[F]) ||
              (df1[AF] + 1 == df2[F] && df1[BF] + 1 == df1[F]))
            t = df3[F];
          else
            t = df2[F];
        else
          t = df1[F];
        ans = max(ans, max(t, uf[F]) + dep[B] - dep[F]);
      }
    } else {
      ans = max(ans, max(Ancfd(A, d), Ancfd(B, dep[B] - dep[F] - 1)));
      if (dep[A] - dep[F] - d - 1 > 0)
        ans = max(ans, Ancfu(M, dep[A] - dep[F] - d - 1) + 1 + dep[B] - dep[F]);
      int AF = Anc(A, dep[A] - dep[F] - 1), BF = Anc(B, dep[B] - dep[F] - 1);
      if (B == F)
        if (df1[AF] + 1 == df1[B])
          ans = max(ans, max(df2[F], uf[F]));
        else
          ans = max(ans, max(df1[F], uf[F]));
      else {
        int t;
        if (df1[AF] + 1 == df1[F] || df1[BF] + 1 == df1[F])
          if ((df1[AF] + 1 == df1[F] && df1[BF] + 1 == df2[F]) ||
              (df1[AF] + 1 == df2[F] && df1[BF] + 1 == df1[F]))
            t = df3[F];
          else
            t = df2[F];
        else
          t = df1[F];
        ans = max(ans, max(t, uf[F]) + dep[B] - dep[F]);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
