#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
inline int read() {
  char c = getchar();
  int x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
int n, m, a[1000005];
struct edge {
  int to, nxt;
} e[1000005 << 1];
int tot, head[1000005];
inline void adde(int u, int v) {
  e[++tot] = (edge){v, head[u]};
  head[u] = tot;
}
int s, t;
int fa[1000005], d[1000005], dis[1000005], cnt;
int dep[1000005], mx[1000005], top[1000005];
bool vis[1000005];
void dfs(int u, int pa) {
  fa[u] = pa;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == pa) continue;
    dis[v] = dis[u] + 1;
    dfs(v, u);
  }
}
void dfs2(int u, int p, int pa) {
  mx[p] = max(mx[p], dep[u]);
  top[u] = p;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == pa || vis[v]) continue;
    dep[v] = dep[u] + 1;
    dfs2(v, p, u);
  }
}
void find() {
  s = t = 1, dis[1] = 0;
  dfs(1, 0);
  for (register int i = (1); i <= (n); ++i)
    if (dis[i] > dis[t]) t = i;
  dis[t] = fa[t] = 0;
  dfs(t, 0);
  for (register int i = (1); i <= (n); ++i)
    if (dis[i] > dis[s]) s = i;
  int u = s;
  while (fa[u]) d[++cnt] = u, vis[u] = 1, u = fa[u];
  d[++cnt] = t;
  vis[t] = 1;
}
inline int p2(int x) { return 1 << x; };
int lg[1000005];
struct RMQ {
  int n, f[1000005][20];
  RMQ() { memset(f, -63, sizeof f); }
  void build() {
    for (register int j = (1); j <= (lg[n]); ++j)
      for (int i = 1; i + p2(j) <= n + 1; i++)
        f[i][j] = max(f[i][j - 1], f[i + p2(j - 1)][j - 1]);
  }
  inline int ask(int l, int r) {
    if (l > r) return -0x3f3f3f3f;
    int len = r - l + 1, k = lg[len];
    return max(f[l][k], f[r - p2(k) + 1][k]);
  }
} f1, f2;
int solve() {
  int u = read(), v = read();
  if (top[u] > top[v]) swap(u, v);
  if (top[u] == top[v])
    return min(dep[u], dep[v]) + max(cnt - top[u], top[u] - 1);
  int len = top[u] + top[v] - dep[u] + dep[v];
  if (top[u] * 2 >= len) return dep[v] + max(top[v] - 1, cnt - top[v]);
  if (top[v] * 2 <= len) return dep[u] + max(top[u] - 1, cnt - top[u]);
  int resx = max(f1.ask(1, len / 2) - top[u], top[u] - 1) + dep[u],
      resy = max(f2.ask(len / 2 + 1, cnt) + top[v], cnt - top[v]) + dep[v];
  return max(resx, resy);
}
signed main() {
  n = read();
  for (register int i = (2); i <= (n); ++i) {
    int u = read(), v = read();
    adde(u, v);
    adde(v, u);
  }
  find();
  for (register int i = (1); i <= (cnt); ++i) dfs2(d[i], i, 0);
  for (register int i = (2); i <= (cnt); ++i) lg[i] = lg[i >> 1] + 1;
  f1.n = f2.n = cnt;
  for (register int i = (1); i <= (cnt); ++i)
    f1.f[i][0] = mx[i] + i, f2.f[i][0] = mx[i] - i;
  f1.build();
  f2.build();
  m = read();
  while (m--) printf("%d\n", solve());
  return 0;
}
