#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, M = 22;
int ans[N], seg[N << 2], lazy[N << 2], H[N], h[N], st[N], fn[N], par[M + 1][N],
    Time, n;
vector<int> g[N];
vector<pair<int, pair<int, int> > > Q[N];
void dfs(int v, int p = 0) {
  st[v] = Time++;
  H[st[v]] = h[v] = h[p] + 1;
  par[0][v] = p;
  for (int i = 1; i <= M; i++) par[i][v] = par[i - 1][par[i - 1][v]];
  for (int u : g[v])
    if (u != p) dfs(u, v);
  fn[v] = Time;
  return;
}
int getpar(int v, int height) {
  for (int i = M; i >= 0; i--)
    if (height & (1 << i)) v = par[i][v];
  return v;
}
int LCA(int u, int v) {
  if (h[u] > h[v]) swap(u, v);
  v = getpar(v, h[v] - h[u]);
  if (u == v) return v;
  for (int i = M; i >= 0; i--)
    if (par[i][v] != par[i][u]) v = par[i][v], u = par[i][u];
  return par[0][v];
}
int dis(int u, int v) { return h[u] + h[v] - h[LCA(u, v)] * 2; }
void Merge(int id) {
  seg[id] = max(seg[id << 1], seg[id << 1 | 1]);
  return;
}
void upd(int id, int val) {
  seg[id] += val;
  lazy[id] += val;
  return;
}
void shift(int id) {
  upd(id << 1, lazy[id]);
  upd(id << 1 | 1, lazy[id]);
  lazy[id] = 0;
  return;
}
void build(int L = 0, int R = n, int id = 1) {
  if (R - L == 1) {
    seg[id] = H[L];
    return;
  }
  int MID = (L + R) / 2;
  build(L, MID, id << 1);
  build(MID, R, id << 1 | 1);
  Merge(id);
  return;
}
void add(int l, int r, int val, int L = 0, int R = n, int id = 1) {
  if (r <= L || R <= l) return;
  if (l <= L && R <= r) {
    upd(id, val);
    return;
  }
  shift(id);
  int MID = (L + R) / 2;
  add(l, r, val, L, MID, id << 1);
  add(l, r, val, MID, R, id << 1 | 1);
  Merge(id);
  return;
}
int get(int l, int r, int L = 0, int R = n, int id = 1) {
  if (r <= L || R <= l) return 0;
  if (l <= L && R <= r) return seg[id];
  shift(id);
  int MID = (L + R) / 2;
  int x1 = get(l, r, L, MID, id << 1);
  int x2 = get(l, r, MID, R, id << 1 | 1);
  Merge(id);
  return max(x1, x2);
}
void solve(int v) {
  for (auto p : Q[v]) {
    int id = p.first, A = p.second.first, b = p.second.second;
    if (b)
      ans[id] = max(ans[id], get(st[A], fn[A]));
    else
      ans[id] = max(ans[id], max(get(0, st[A]), get(fn[A], n)));
  }
  for (int u : g[v])
    if (u != par[0][v]) {
      add(0, n, 1);
      add(st[u], fn[u], -2);
      solve(u);
      add(0, n, -1);
      add(st[u], fn[u], 2);
    }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  h[0] = -1;
  dfs(1);
  build();
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int u, v;
    cin >> u >> v;
    if (h[u] > h[v]) swap(u, v);
    int d = (dis(u, v) - 1) / 2;
    int A = getpar(v, d);
    Q[v].push_back({i, {A, 1}});
    Q[u].push_back({i, {A, 0}});
  }
  solve(1);
  for (int i = 0; i < q; i++) cout << ans[i] << "\n";
  return 0;
}
