#include <bits/stdc++.h>
const int N = 100000 + 5;
const int LOG = 18;
const int INF = 0x3f3f3f3f;
int depth[N], n, nq, plca[LOG][N], parent[N];
int subtree_max[N][4], antisubtree_max[N];
std::vector<int> edges[N];
std::vector<std::pair<int, int> > queries[N];
int answer[N];
struct SegmentTree {
  int t[N << 2];
  void modify(int p, int v, int l, int r, int rt) {
    if (l == r) {
      t[rt] = v;
      return;
    }
    int mid = l + r >> 1;
    if (p <= mid)
      modify(p, v, l, mid, rt << 1);
    else
      modify(p, v, mid + 1, r, rt << 1 | 1);
    t[rt] = std::max(t[rt << 1], t[rt << 1 | 1]);
  }
  int query(int L, int R, int l, int r, int rt) {
    if (L > R) return -INF;
    if (L <= l && r <= R) {
      return t[rt];
    }
    int mid = l + r >> 1;
    int ret = -INF;
    if (L <= mid) ret = std::max(ret, query(L, R, l, mid, rt << 1));
    if (mid < R) ret = std::max(ret, query(L, R, mid + 1, r, rt << 1 | 1));
    return ret;
  }
} down, up;
int jump(int u, int length) {
  for (int i = 0; i < LOG; ++i) {
    if (length >> i & 1) u = plca[i][u];
  }
  return u;
}
int getLCA(int a, int b) {
  if (depth[a] < depth[b]) std::swap(a, b);
  for (int i = 0; i < LOG; ++i) {
    if (depth[a] - depth[b] >> i & 1) a = plca[i][a];
  }
  for (int i = LOG - 1; i >= 0; --i) {
    if (plca[i][a] != plca[i][b]) {
      a = plca[i][a];
      b = plca[i][b];
    }
  }
  return a == b ? a : plca[0][a];
}
void dfs(int u) {
  for (__typeof((edges[u]).begin()) it = (edges[u]).begin();
       it != (edges[u]).end(); ++it) {
    int v = *it;
    if (v == parent[u]) continue;
    int value = subtree_max[u][0];
    if (value == subtree_max[v][0] + 1) value = subtree_max[u][1];
    down.modify(depth[u], value - depth[u], 0, n, 1);
    up.modify(depth[u], value + depth[u], 0, n, 1);
    dfs(v);
  }
  for (__typeof((queries[u]).begin()) it = (queries[u]).begin();
       it != (queries[u]).end(); ++it) {
    int v = it->first;
    int id = it->second;
    int lca = getLCA(u, v);
    if (u == lca) continue;
    if (depth[u] <= depth[v]) {
      answer[id] = std::max(
          answer[id],
          down.query(depth[lca] + 1, depth[u] - 1, 0, n, 1) + depth[u]);
      answer[id] = std::max(answer[id], subtree_max[u][0]);
      answer[id] =
          std::max(answer[id], antisubtree_max[lca] - depth[lca] + depth[u]);
      int su = jump(u, depth[u] - depth[lca] - 1);
      int sv = jump(v, depth[v] - depth[lca] - 1);
      int value = subtree_max[lca][0];
      if (value == subtree_max[su][0] + 1) {
        value = subtree_max[lca][1];
        if (value == subtree_max[sv][0] + 1) {
          value = subtree_max[lca][2];
        }
      } else if (value == subtree_max[sv][0] + 1) {
        value = subtree_max[lca][1];
        if (value == subtree_max[su][0] + 1) {
          value = subtree_max[lca][2];
        }
      }
      answer[id] = std::max(answer[id], value - depth[lca] + depth[u]);
    } else {
      int key = (depth[u] - depth[v] + 1) / 2 + depth[lca];
      answer[id] = std::max(answer[id],
                            down.query(key, depth[u] - 1, 0, n, 1) + depth[u]);
      answer[id] =
          std::max(answer[id], up.query(depth[lca] + 1, key - 1, 0, n, 1) -
                                   depth[lca] + depth[v] - depth[lca]);
      answer[id] = std::max(answer[id], subtree_max[u][0]);
      if (lca == v) {
        answer[id] = std::max(answer[id], antisubtree_max[lca]);
        int value = subtree_max[lca][0];
        int su = jump(u, depth[u] - depth[lca] - 1);
        if (value == subtree_max[su][0] + 1) {
          value = subtree_max[lca][1];
        }
        answer[id] = std::max(answer[id], value);
      }
    }
  }
}
void solve() {
  static int queue[N];
  int qe = 0;
  queue[qe++] = 0;
  parent[0] = -1;
  for (int qf = 0; qf != qe; ++qf) {
    int u = queue[qf];
    plca[0][u] = parent[u];
    for (int i = 1; i < LOG; ++i) {
      plca[i][u] = -1;
      if (plca[i - 1][u] != -1) plca[i][u] = plca[i - 1][plca[i - 1][u]];
    }
    for (__typeof((edges[u]).begin()) it = (edges[u]).begin();
         it != (edges[u]).end(); ++it) {
      int v = *it;
      if (v == parent[u]) continue;
      queue[qe++] = v;
      parent[v] = u;
      depth[v] = depth[u] + 1;
    }
  }
  memset(subtree_max, 0, sizeof(subtree_max));
  memset(antisubtree_max, 0, sizeof(antisubtree_max));
  for (int I = qe - 1; I >= 1; --I) {
    int u = queue[I];
    int father = parent[u];
    subtree_max[father][3] = subtree_max[u][0] + 1;
    std::sort(subtree_max[father], subtree_max[father] + 4,
              std::greater<int>());
  }
  for (int I = 1; I < qe; ++I) {
    int u = queue[I];
    int father = parent[u];
    int value = subtree_max[father][0];
    if (value == subtree_max[u][0] + 1) value = subtree_max[father][1];
    antisubtree_max[u] = std::max(value, antisubtree_max[father]) + 1;
  }
  dfs(0);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  scanf("%d", &nq);
  for (int i = 0; i < nq; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    queries[a].push_back(std::make_pair(b, i));
    queries[b].push_back(std::make_pair(a, i));
  }
  solve();
  for (int i = 0; i < nq; ++i) {
    printf("%d\n", answer[i]);
  }
  return 0;
}
