#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  bool fl = false;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') fl = true, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
  return fl ? -x : x;
}
struct Line {
  int v, next;
} e[100100 << 1];
int h[100100], cnt = 1, fa[100100];
inline void Add(int u, int v) {
  e[cnt] = (Line){v, h[u]};
  h[u] = cnt++;
}
int n, m, x, y, lans, r1, r2;
long long ans;
bool vis[100100];
int BFS(int S) {
  queue<int> Q;
  Q.push(S);
  int ret = S;
  fa[S] = 0;
  memset(vis, 0, sizeof(vis));
  vis[S] = true;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    ret = u;
    for (int i = h[u]; i; i = e[i].next)
      if (!vis[e[i].v]) vis[e[i].v] = true, fa[e[i].v] = u, Q.push(e[i].v);
  }
  return ret;
}
int lg[100100], S[100100], top, md[100100], dep[100100], bh[100100];
void dfs(int u, int ff, int rt) {
  dep[u] = dep[ff] + 1;
  md[rt] = max(md[rt], dep[u]);
  bh[u] = rt;
  for (int i = h[u]; i; i = e[i].next)
    if (e[i].v != ff && !vis[e[i].v]) dfs(e[i].v, u, rt);
}
int s[2][20][100100];
void pre() {
  memset(vis, 0, sizeof(vis));
  for (int i = 2; i <= n; ++i) lg[i] = lg[i >> 1] + 1;
  for (int i = r2; i; i = fa[i]) vis[i] = true, S[++top] = i, bh[i] = top;
  for (int i = 1; i <= top; ++i) dfs(S[i], 0, i);
  memset(s, -63, sizeof(s));
  for (int i = 1; i <= top; ++i) s[0][0][i] = md[i] - i, s[1][0][i] = md[i] + i;
  for (int k = 0; k < 2; ++k)
    for (int j = 1; j < 20; ++j)
      for (int i = 1; (i + (1 << (j - 1))) <= top; ++i)
        s[k][j][i] = max(s[k][j - 1][i], s[k][j - 1][i + (1 << (j - 1))]);
}
int ST(int l, int r, int p) {
  if (l > r) return -1e9;
  int k = lg[r - l + 1];
  return max(s[p][k][l], s[p][k][r - (1 << k) + 1]);
}
int main() {
  n = read();
  for (int i = 1; i < n; ++i) {
    int u = read(), v = read();
    Add(u, v);
    Add(v, u);
  }
  r1 = BFS(1);
  r2 = BFS(r1);
  dep[0] = -1;
  pre();
  m = read();
  while (m--) {
    x = read(), y = read();
    int l = bh[x], r = bh[y], dis;
    if (l > r) swap(l, r), swap(x, y);
    if (l == r)
      lans = max(l - 1, top - l) + min(dep[x], dep[y]);
    else {
      dis = (l + r - dep[x] + dep[y]);
      if (dis <= l * 2)
        lans = max(r - 1, top - r) + dep[y];
      else if (dis >= r * 2)
        lans = max(l - 1, top - l) + dep[x];
      else
        dis /= 2, lans = max(max(l - 1, ST(l + 1, dis, 1) - l) + dep[x],
                             max(top - r, ST(dis + 1, r - 1, 0) + r) + dep[y]);
    }
    printf("%d\n", lans);
  }
  return 0;
}
