#include <bits/stdc++.h>
using namespace std;
namespace IO {
const int maxn(1 << 21 | 1);
char ibuf[maxn], *iS, *iT, c;
int f;
inline char Getc() {
  return iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, maxn, stdin),
                     (iS == iT ? EOF : *iS++))
                  : *iS++;
}
template <class Int>
inline void In(Int &x) {
  for (f = 1, c = Getc(); c < '0' || c > '9'; c = Getc()) f = c == '-' ? -1 : 1;
  for (x = 0; c >= '0' && c <= '9'; c = Getc())
    x = (x << 1) + (x << 3) + (c ^ 48);
  x *= f;
}
}  // namespace IO
using IO ::In;
const int maxn(1e5 + 5);
int n, first[maxn], cnt, m, xx, yy, dis[maxn], pre[maxn], lg[maxn], tmp[maxn];
int f[20][maxn], g[20][maxn], bel[maxn], l, r, id[maxn], tot, pos[maxn];
long long zip;
struct Edge {
  int to, next;
} edge[maxn << 1];
inline void Add(int u, int v) {
  edge[cnt] = (Edge){v, first[u]}, first[u] = cnt++;
  edge[cnt] = (Edge){u, first[v]}, first[v] = cnt++;
}
void Dfs1(int u, int ff) {
  for (int e = first[u], v; ~e; e = edge[e].next)
    if ((v = edge[e].to) != ff) pre[v] = u, dis[v] = dis[u] + 1, Dfs1(v, u);
}
void Dfs2(int u, int rt, int ff) {
  if (pos[u] || bel[u]) {
    bel[rt] = pos[u] ? pos[u] : bel[u];
    return;
  }
  for (int e = first[u], v; ~e; e = edge[e].next)
    if ((v = edge[e].to) != ff) Dfs2(v, rt, u);
}
inline int RMQ_F(int l, int r) {
  if (l > r) return 0;
  int len = lg[r - l + 1];
  return max(f[len][l], f[len][r - (1 << len) + 1]);
}
inline int RMQ_G(int l, int r) {
  if (l > r) return 0;
  int len = lg[r - l + 1];
  return max(g[len][l], g[len][r - (1 << len) + 1]);
}
int main() {
  memset(first, -1, sizeof(first));
  In(n);
  for (int i = 1, u, v; i < n; ++i) In(u), In(v), Add(u, v);
  dis[1] = 0, Dfs1(1, 0);
  for (int i = 1; i <= n; ++i)
    if (!l || dis[i] > dis[l]) l = i;
  dis[l] = 0, Dfs1(l, 0);
  for (int i = 1; i <= n; ++i)
    if (!r || dis[i] > dis[r]) r = i;
  for (int i = r; i != l; i = pre[i]) id[++tot] = i;
  id[++tot] = l, reverse(id + 1, id + tot + 1);
  for (int i = 1; i <= tot; ++i) pos[id[i]] = i;
  for (int i = 2; i <= tot; ++i) lg[i] = lg[i >> 1] + 1;
  for (int i = 1; i <= n; ++i) Dfs2(i, i, 0), tmp[i] = dis[i];
  for (int i = 1; i <= n; ++i) f[0][bel[i]] = max(f[0][bel[i]], dis[i]);
  dis[r] = 0, Dfs1(r, 0);
  for (int i = 1; i <= n; ++i) g[0][bel[i]] = max(g[0][bel[i]], dis[i]);
  for (int j = 1; j <= lg[tot]; ++j)
    for (int i = 1; i + (1 << j) - 1 <= tot; ++i) {
      f[j][i] = max(f[j - 1][i], f[j - 1][i + (1 << (j - 1))]);
      g[j][i] = max(g[j - 1][i], g[j - 1][i + (1 << (j - 1))]);
    }
  In(m);
  for (int i = 1, ans = 0, lx = xx, ly = yy; i <= m; ++i) {
    In(xx), In(yy);
    if (bel[xx] > bel[yy]) swap(xx, yy);
    if (bel[xx] != bel[yy]) {
      int u = xx, v = yy, dx = tmp[xx] - 2 * tmp[id[bel[xx]]],
          dy = dis[yy] - 2 * dis[id[bel[yy]]];
      int tmpd = tmp[xx] - tmp[id[bel[xx]]],
          d = tmpd + dis[yy] - dis[id[bel[yy]]];
      xx = bel[xx], yy = bel[yy], d += yy - xx;
      int mid = xx + ((d + 1) >> 1) - 1 - tmpd;
      if (mid >= xx && mid < yy) {
        dx += RMQ_F(xx, mid), dy += RMQ_G(mid + 1, yy);
        ans = max(max(tmp[u], dis[v]), max(dx, dy));
      } else if (mid < xx)
        ans = max(tmp[v], dis[v]);
      else
        ans = max(tmp[u], dis[u]);
    } else {
      ans = min(max(dis[xx], tmp[yy]), max(dis[yy], tmp[xx]));
      ans = min(ans, min(max(dis[xx], tmp[xx]), max(dis[yy], tmp[yy])));
    }
    printf("%d\n", ans);
  }
  return 0;
}
