#include <bits/stdc++.h>
using namespace std;
const int _ = 1e5 + 5;
inline int read() {
  char ch = getchar();
  int x = 0, q = 0;
  while (ch < '0' || ch > '9') q = ch == '-' ? 1 : q, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return q ? -x : x;
}
int n, m, S, T;
struct ed {
  int to, next;
} e[_ << 1];
int cnt, head[_];
void link(int u, int v) {
  e[++cnt] = (ed){v, head[u]};
  head[u] = cnt;
  e[++cnt] = (ed){u, head[v]};
  head[v] = cnt;
}
queue<int> Q;
int d[_], fa[_];
bool vis[_];
int bfs(int S) {
  memset(vis, 0, sizeof(vis));
  memset(fa, 0, sizeof(fa));
  Q.push(S);
  d[S] = 1;
  vis[S] = 1;
  int Mx = 0, Mxx = 0;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    if (d[u] > Mxx) Mxx = d[u], Mx = u;
    for (int i = head[u]; i; i = e[i].next) {
      int v = e[i].to;
      if (!vis[v]) vis[v] = 1, d[v] = d[u] + 1, Q.push(v), fa[v] = u;
    }
  }
  return Mx;
}
int tp[_], f[_], dep[_], l[_];
bool mark[_];
void dfs(int u, int fa, int up) {
  tp[u] = up;
  f[up] = max(f[up], dep[u]);
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa || mark[v]) continue;
    dep[v] = dep[u] + 1;
    dfs(v, u, up);
  }
}
int g[2][_][20], lg[_];
void Pre() {
  for (int i = 2; i <= n; ++i) lg[i] = lg[i >> 1] + 1;
  for (int i = 1; i <= l[0]; ++i) g[0][i][0] = f[i] + i, g[1][i][0] = f[i] - i;
  for (int op = 0; op < 2; ++op)
    for (int j = 1; j <= 17; ++j)
      for (int i = 1; i + (1 << j) - 1 <= l[0]; ++i)
        g[op][i][j] = max(g[op][i][j - 1], g[op][i + (1 << (j - 1))][j - 1]);
}
int qy(int op, int l, int r) {
  if (l > r) return -1e9;
  int k = lg[r - l + 1];
  return max(g[op][l][k], g[op][r - (1 << k) + 1][k]);
}
int main() {
  n = read();
  for (int u, v, i = 1; i < n; ++i) u = read(), v = read(), link(u, v);
  S = bfs(1);
  T = bfs(S);
  for (int i = T; i != S; i = fa[i]) mark[i] = 1, l[++l[0]] = i;
  mark[S] = 1;
  l[++l[0]] = S;
  for (int i = 1; i <= l[0]; ++i) dfs(l[i], 0, i);
  m = read();
  Pre();
  int s = 0;
  while (m--) {
    int x = read(), y = read();
    if (tp[x] == tp[y])
      s = max(tp[x] - 1, l[0] - tp[x]) + min(dep[x], dep[y]);
    else {
      if (tp[x] > tp[y]) swap(x, y);
      int mid = (tp[x] - dep[x] + tp[y] + dep[y]);
      if (mid <= tp[x] * 2)
        s = max(tp[y] - 1, l[0] - tp[y]) + dep[y];
      else if (mid >= tp[y] * 2)
        s = max(tp[x] - 1, l[0] - tp[x]) + dep[x];
      else {
        mid >>= 1;
        int t1 = max(tp[x] - 1, qy(0, tp[x] + 1, mid) - tp[x]) + dep[x];
        int t2 = max(l[0] - tp[y], qy(1, mid + 1, tp[y] - 1) + tp[y]) + dep[y];
        s = max(t1, t2);
      }
    }
    printf("%d\n", s);
  }
  return 0;
}
