#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, const U &b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, const U &b) {
  if (a < b) a = b;
}
const int NN = 2e5 + 10;
int n;
int E, head[NN], to[NN << 1], nxt[NN << 1];
int nn, qf, qb, q[NN], sz[NN], fa[NN], vst[NN];
void init(int n) {
  E = 0;
  for (int i = 1; i <= n; i++) {
    head[i] = -1, vst[i] = 0;
  }
}
inline void add(int u, int v) {
  nxt[E] = head[u];
  to[E] = v;
  head[u] = E++;
  nxt[E] = head[v];
  to[E] = u;
  head[v] = E++;
}
int p[NN][20], deep[NN];
struct LCA {
  void dfs(int u, int fa = 0) {
    deep[u] = deep[fa] + 1;
    p[u][0] = fa;
    for (int i = 0; i < 19; i++) p[u][i + 1] = p[p[u][i]][i];
    for (int e = head[u]; ~e; e = nxt[e]) {
      int v = to[e];
      if (v == fa) continue;
      dfs(v, u);
    }
  }
  int k_th(int u, int k) {
    for (; k; k -= k & -k) u = p[u][(__builtin_ctz(k))];
    return u;
  }
  int lca(int u, int v) {
    if (deep[u] < deep[v]) swap(u, v);
    u = k_th(u, deep[u] - deep[v]);
    if (u == v) return u;
    for (int i = 20; i--;) {
      if (p[u][i] != p[v][i]) u = p[u][i], v = p[v][i];
    }
    return p[u][0];
  }
} lca;
int get_root(int u) {
  qf = qb = 0;
  q[qb++] = u;
  fa[u] = 0;
  while (qf < qb) {
    u = q[qf++];
    for (int e = head[u]; ~e; e = nxt[e]) {
      int v = to[e];
      if (v == fa[u] || vst[v]) continue;
      fa[v] = u;
      q[qb++] = v;
    }
  }
  nn = qb;
  for (int i = nn; i--;) {
    sz[u = q[i]] = 1;
    int mx = 0;
    for (int e = head[u]; ~e; e = nxt[e]) {
      int v = to[e];
      if (v == fa[u] || vst[v]) continue;
      smax(mx, sz[v]);
      sz[u] += sz[v];
    }
    if (mx * 2 <= nn && sz[u] * 2 >= nn) return u;
  }
}
int mxdeep(int u, int fa = 0) {
  int ans = 0;
  for (int e = head[u]; ~e; e = nxt[e]) {
    int v = to[e];
    if (v == fa || vst[v]) continue;
    smax(ans, mxdeep(v, u) + 1);
  }
  return ans;
}
int pool[NN * 40], *cur;
int cnt;
struct BIT {
  int n;
  int *A;
  void init(int n) {
    this->n = n;
    A = cur;
    for (int i = 0; i < n; i++) A[i] = 0;
    cur += n;
  }
  void sum() {
    for (int i = 1; i < n; i++) A[i] += A[i - 1];
  }
  int get(int d) {
    smin(d, n - 1);
    if (d < 0) return 0;
    return A[d];
  }
} Arr[NN << 1];
struct Data {
  int root, sub, deep;
  Data(int root, int sub, int deep) : root(root), sub(sub), deep(deep) {}
};
vector<Data> vec[NN];
void dfs(int u, int root, int sub, int deep, int fa = 0) {
  vec[u].push_back(Data(root, sub, deep));
  if (u <= n) {
    Arr[root].A[deep]++;
    Arr[sub].A[deep]++;
  }
  for (int e = head[u]; ~e; e = nxt[e]) {
    int v = to[e];
    if (v == fa || vst[v]) continue;
    dfs(v, root, sub, deep + 1, u);
  }
}
void solve(int u) {
  u = get_root(u);
  nn = mxdeep(u) + 1;
  vst[u] = 1;
  int id = ++cnt;
  Arr[id].init(nn);
  vec[u].push_back(Data(id, 0, 0));
  if (u <= n) Arr[id].A[0]++;
  for (int e = head[u]; ~e; e = nxt[e]) {
    int v = to[e];
    if (vst[v]) continue;
    cnt++;
    Arr[cnt].init(nn);
    dfs(v, id, cnt, 1, u);
    Arr[cnt].sum();
  }
  Arr[id].sum();
  for (int e = head[u]; ~e; e = nxt[e]) {
    int v = to[e];
    if (vst[v]) continue;
    solve(v);
  }
}
inline int calc(int u, int d) {
  int ans = 0;
  for (int i = 0; i < vec[u].size(); i++) {
    ans += Arr[vec[u][i].root].get(d - vec[u][i].deep);
    ans -= Arr[vec[u][i].sub].get(d - vec[u][i].deep);
  }
  return ans;
}
int main() {
  int md, m;
  scanf("%d", &n);
  init(n << 1);
  md = n;
  for (int i = 1, u, v; i < n; i++) {
    md++;
    scanf("%d %d", &u, &v);
    add(u, md);
    add(md, v);
  }
  lca.dfs(1);
  cnt = 0;
  cur = pool;
  solve(1);
  scanf("%d", &m);
  for (int u, v, st, ed, d, t, dst; m--;) {
    scanf("%d %d", &u, &v);
    for (st = -1, ed = n; st + 1 < ed;) {
      d = (st + ed >> 1) << 1;
      dst = deep[u] + deep[v] - 2 * deep[lca.lca(u, v)];
      t = calc(u, d) + calc(v, d);
      if (d * 2 >= dst) {
        if (deep[u] > deep[v]) {
          t -= calc(lca.k_th(u, dst / 2), d - dst / 2);
        } else {
          t -= calc(lca.k_th(v, dst / 2), d - dst / 2);
        }
      }
      d >>= 1;
      if (t == n) {
        ed = d;
      } else {
        st = d;
      }
    }
    printf("%d\n", ed);
  }
  return 0;
}
