#include <bits/stdc++.h>
using namespace std;
const int _ = 1e5 + 20;
int a[_], to[_ << 1], nex[_ << 1], w[_], vis[_], p[_], root[_], mi[20][_],
    ma[20][_], fz[_], b, c, s1, s2, n, m;
int dep[_], d[_], ans;
long long Ans;
void dfs(int fa, int u, int d) {
  if (d > b) c = u, b = d;
  for (int i = a[u]; i; i = nex[i]) {
    int v = to[i];
    if (v == fa) continue;
    dfs(u, v, d + 1);
  }
}
void Dfs(int fa, int u) {
  if (u == s1) {
    root[++m] = u;
    vis[u] = 1;
    return;
  }
  for (int i = a[u]; i; i = nex[i]) {
    int v = to[i];
    if (v == fa) continue;
    Dfs(u, v);
    if (m) {
      root[++m] = u;
      vis[u] = 1;
      return;
    }
  }
}
void DFS(int fa, int u, int kk) {
  w[u] = kk;
  dep[u] = dep[fa] + 1;
  d[kk] = max(d[kk], dep[u]);
  for (int i = a[u]; i; i = nex[i]) {
    int v = to[i];
    if (v == fa || vis[v]) continue;
    DFS(u, v, kk);
  }
}
int query(int l, int r, int opt) {
  if (r < l) return -1e9;
  int k = fz[r - l + 1];
  if (opt)
    return max(mi[k][l], mi[k][r - (1 << k) + 1]);
  else
    return max(ma[k][l], ma[k][r - (1 << k) + 1]);
}
void init() {
  for (int i = 1; i <= m; ++i) DFS(0, root[i], i);
  for (int i = 1; i <= m; ++i) mi[0][i] = d[i] - i;
  for (int i = 1; i <= m; ++i) ma[0][i] = d[i] + i;
  for (int i = 1; i <= 18; ++i)
    for (int j = 1; j <= m; ++j) {
      int k = j + (1 << i - 1);
      if (k <= m)
        mi[i][j] = max(mi[i - 1][j], mi[i - 1][k]),
        ma[i][j] = max(ma[i - 1][j], ma[i - 1][k]);
      else
        break;
    }
  for (int i = 1; i <= m; ++i) fz[i] = log2(i);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1, t = 0; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    nex[++t] = a[u];
    to[t] = v;
    a[u] = t;
    nex[++t] = a[v];
    to[t] = u;
    a[v] = t;
  }
  dep[0] = -1;
  dfs(0, 1, 1);
  s1 = c;
  b = c = 0;
  dfs(0, s1, 1);
  s2 = c;
  Dfs(0, s2);
  init();
  int q, X, Y;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    int s;
    if (w[x] > w[y]) swap(x, y);
    if (w[x] == w[y]) {
      ans = max(w[x] - 1, m - w[x]) + min(dep[x], dep[y]);
      printf("%d\n", ans);
      continue;
    }
    s = (w[x] - dep[x] + w[y] + dep[y]);
    if (s <= w[x] * 2) {
      ans = max(w[y] - 1, m - w[y]) + dep[y];
      printf("%d\n", ans);
      continue;
    }
    if (s >= w[y] * 2) {
      ans = max(w[x] - 1, m - w[x]) + dep[x];
      printf("%d\n", ans);
      continue;
    }
    s /= 2;
    ans = max(max(w[x] - 1, query(w[x] + 1, s, 0) - w[x]) + dep[x],
              dep[y] + max(m - w[y], query(s + 1, w[y] - 1, 1) + w[y]));
    printf("%d\n", ans);
  }
  return 0;
}
