#include <bits/stdc++.h>
using namespace std;
int son[100010][2], fa[100010], is[100010], cnt[100010], dep[100010],
    maxdep[100010];
int maxdis[100010], mydis[100010];
int pfa[100010];
multiset<int> st[100010];
inline void up(int x) {
  cnt[x] = cnt[son[x][0]] + cnt[son[x][1]] + 1;
  maxdep[x] = max(max(dep[x], *st[x].rbegin()),
                  max(maxdep[son[x][0]], maxdep[son[x][1]]));
  mydis[x] = max(dep[x], *st[x].rbegin()) - 2 * dep[x];
  maxdis[x] = max(mydis[x], max(maxdis[son[x][0]], maxdis[son[x][1]]));
}
inline void Rotate(int x) {
  int y = fa[x], z = fa[y];
  int r = son[y][1] == x;
  son[y][r] = son[x][!r], fa[son[y][r]] = y;
  son[x][!r] = y, fa[y] = x;
  fa[x] = z;
  if (is[y])
    is[y] = 0, is[x] = 1;
  else
    son[z][son[z][1] == y] = x;
  up(y);
}
inline void Splay(int x) {
  int y, z;
  while (!is[x]) {
    y = fa[x], z = fa[y];
    if (is[y])
      Rotate(x);
    else if ((son[y][1] == x) ^ (son[z][1] == y))
      Rotate(x), Rotate(x);
    else
      Rotate(y), Rotate(x);
  }
  up(x);
}
inline int Access(int x) {
  int y;
  for (y = 0; x; x = fa[y = x]) {
    Splay(x);
    if (son[x][1]) {
      is[son[x][1]] = 1;
      st[x].insert(maxdep[son[x][1]]);
    }
    is[son[x][1] = y] = 0;
    if (y) {
      st[x].erase(st[x].find(maxdep[y]));
    }
    up(x);
  }
  return y;
}
int lca(int u, int v) {
  Access(u);
  return Access(v);
}
int jump(int x, int d) {
  Access(x);
  while (x) {
    if (cnt[son[x][1]] == d)
      return x;
    else if (cnt[son[x][1]] > d)
      x = son[x][1];
    else
      d -= cnt[son[x][1]] + 1, x = son[x][0];
  }
  return x;
}
void link(int u, int v) {
  if (dep[u] > dep[v]) swap(u, v);
  Access(u);
  Splay(v);
  fa[v] = u;
  st[u].insert(maxdep[v]);
  Splay(u);
}
void cut(int u, int v) {
  if (dep[u] > dep[v]) swap(u, v);
  Access(u);
  Splay(v);
  fa[v] = 0;
  st[u].erase(st[u].find(maxdep[v]));
  Splay(u);
}
int vv[100010 << 1], nxt[100010 << 1], h[100010], e;
void add(int u, int v) {
  vv[e] = v, nxt[e] = h[u], h[u] = e++;
  vv[e] = u, nxt[e] = h[v], h[v] = e++;
}
int gao(int u) {
  int x = Access(u);
  return maxdis[x] + dep[u];
}
void dfs(int u, int f) {
  pfa[u] = f;
  cnt[u] = is[u] = 1;
  st[u].insert(0);
  int v;
  for (int i = h[u]; i + 1; i = nxt[i]) {
    v = vv[i];
    if (v == f) continue;
    maxdep[v] = dep[v] = dep[u] + 1;
    mydis[v] = maxdis[v] = -dep[v];
    dfs(v, u);
  }
}
int solve(int u, int v) {
  if (u == v) return gao(u);
  int f = lca(u, v);
  int d = dep[u] + dep[v] - 2 * dep[f];
  int hd = (d - 1) / 2;
  int x, y;
  if (dep[u] - dep[f] > hd) {
    x = jump(u, hd);
    y = jump(x, 1);
  } else {
    x = jump(v, hd);
    y = jump(x, 1);
  }
  cut(y, x);
  int ans = max(gao(u), gao(v));
  link(y, x);
  return ans;
}
int main() {
  int n, m, u, v;
  scanf("%d", &n);
  memset(h, -1, sizeof(h)), e = 0;
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &u, &v);
    add(u, v);
  }
  dfs(1, 1);
  maxdep[0] = maxdis[0] = -0x3f3f3f3f;
  cnt[0] = 0;
  for (int i = 2; i <= n; ++i) link(pfa[i], i);
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &u, &v);
    printf("%d\n", solve(u, v));
  }
}
