#include <bits/stdc++.h>
inline int in() {
  int k = 0;
  char ch = getchar();
  while (ch < '-') ch = getchar();
  while (ch > '-') k = k * 10 + ch - '0', ch = getchar();
  return k;
}
const int N = 1e5 + 5;
int head[N], to[N << 1], nxt[N << 1], cnt, s1, s2, dis[N], c, dd, m, rt[N], n,
    w[N], dep[N], d[N];
int st[N][20], ts[N][20], Log[N], o[N];
inline void add(int u, int v) {
  to[++cnt] = v, nxt[cnt] = head[u], head[u] = cnt;
  to[++cnt] = u, nxt[cnt] = head[v], head[v] = cnt;
}
using std::max;
using std::min;
void dfs(int u, int pa = 0) {
  dis[u] = dis[pa] + 1;
  if (dis[u] > dd) dd = dis[u], c = u;
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != pa) dfs(to[i], u);
}
void Dfs(int u, int pa = 0) {
  if (u == s1) {
    rt[++m] = u;
    o[u] = 1;
    return;
  }
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != pa) {
      Dfs(to[i], u);
      if (m) {
        rt[++m] = u;
        o[u] = 1;
        return;
      }
    }
}
void DFS(int u, int k, int pa = 0) {
  w[u] = k;
  dep[u] = dep[pa] + 1;
  d[k] = max(d[k], dep[u]);
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != pa && !o[to[i]]) DFS(to[i], k, u);
}
void init() {
  for (int i = 1; i <= m; ++i) DFS(rt[i], i);
  for (int i = 1; i <= m; ++i) st[i][0] = d[i] - i;
  for (int i = 1; i <= m; ++i) ts[i][0] = d[i] + i;
  for (int i = 2; i <= m; ++i) Log[i] = Log[i >> 1] + 1;
  for (int j = 1; (1 << j) <= m; ++j)
    for (int i = 1; i + (1 << j) <= m + 1; ++i)
      st[i][j] = max(st[i][j - 1], st[i + (1 << j - 1)][j - 1]),
      ts[i][j] = max(ts[i][j - 1], ts[i + (1 << j - 1)][j - 1]);
}
inline int RMQ(int x, int y, int opt) {
  if (x > y) return -1e9;
  int k = Log[y - x + 1];
  return opt ? max(st[x][k], st[y - (1 << k) + 1][k])
             : max(ts[x][k], ts[y - (1 << k) + 1][k]);
}
inline int query(int x, int y) {
  if (w[x] > w[y]) std::swap(x, y);
  if (w[x] == w[y]) return max(w[x] - 1, m - w[x]) + min(dep[x], dep[y]);
  int s = w[x] - dep[x] + dep[y] + w[y];
  if (s <= w[x] * 2) return max(w[y] - 1, m - w[y]) + dep[y];
  if (s >= w[y] * 2) return max(w[x] - 1, m - w[x]) + dep[x];
  s >>= 1;
  return max(max(w[x] - 1, RMQ(w[x] + 1, s, 0) - w[x]) + dep[x],
             max(m - w[y], RMQ(s + 1, w[y] - 1, 1) + w[y]) + dep[y]);
}
int main() {
  n = in();
  for (int i = 1; i < n; ++i) add(in(), in());
  int Q = in();
  dfs(1);
  s1 = c, dd = 0;
  dfs(s1);
  s2 = c;
  Dfs(s2);
  dep[0] = -1;
  init();
  while (Q--) printf("%d\n", query(in(), in()));
  return 0;
}
