#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int dis[N], ls[N], bl[N];
vector<int> G[N];
int bfs(int x, int fa = 0) {
  static int q[N], t, w;
  dis[x] = 1;
  t = -1;
  w = -1;
  ls[x] = bl[x] = fa;
  q[++w] = x;
  for (; t < w;) {
    int u = q[++t];
    for (int i : G[u])
      if (i != ls[u]) dis[i] = dis[u] + 1, ls[i] = u, bl[i] = fa, q[++w] = i;
  }
  return q[w];
}
const int inf = 1e9;
template <typename T>
int query(T f, int l, int r) {
  if (l >= r) return -inf;
  int k = 31 - __builtin_clz(r - l);
  return max(f[k][l], f[k][r - (1 << k)]);
}
int n, q, f[20][N], g[20][N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  int u = bfs(1), v = bfs(u), L = dis[v];
  for (int i = v, la = 0; i; la = i, i = ls[i]) {
    int mx = 0;
    bl[i] = i;
    for (int j : G[i])
      if (j != la && j != ls[i]) mx = max(mx, dis[bfs(j, i)]);
    f[0][dis[i]] = mx + dis[i];
    g[0][dis[i]] = mx - dis[i];
  }
  for (int i = 1; (1 << i) <= L; ++i)
    for (int j = 1; j + (1 << i) - 1 <= L; ++j)
      f[i][j] = max(f[i - 1][j], f[i - 1][j + (1 << (i - 1))]),
      g[i][j] = max(g[i - 1][j], g[i - 1][j + (1 << (i - 1))]);
  for (cin >> q; q-- > 0;) {
    int x, y, l, r, mid, tl = 0, tr = 0;
    cin >> x >> y;
    l = dis[bl[x]];
    r = dis[bl[y]];
    if (l > r) swap(l, r), swap(x, y);
    if (bl[x] != x) l -= dis[x], tl = dis[x], x = bl[x];
    if (bl[y] != y) r += dis[y], tr = dis[y], y = bl[y];
    mid = (l + r) / 2 + 1;
    int ans1 = max(min(tl - dis[x], tr - dis[y]) + L,
                   min(tl + dis[x], tr + dis[y]) - 1);
    int ans2 = max(query(f, dis[x] + 1, min(mid, dis[y])) - l,
                   query(g, max(dis[x] + 1, mid), dis[y]) + r);
    cout << max(ans1, ans2) << '\n';
  }
  return 0;
}
