#include <bits/stdc++.h>
using namespace std;
long long n, m, par[((long long)20)][((long long)101 * 1000)],
    dis[((long long)101 * 1000)], strt[((long long)101 * 1000)],
    fnsh[((long long)101 * 1000)], _cnt, ans[((long long)101 * 1000)],
    r_strt[((long long)101 * 1000)];
vector<long long> e[((long long)101 * 1000)];
vector<pair<long long, long long> > qu[((long long)101 * 1000)];
long long seg[4 * ((long long)101 * 1000)], lazy[4 * ((long long)101 * 1000)];
void pre_dfs(long long x) {
  r_strt[_cnt] = x;
  strt[x] = _cnt++;
  for (int i = 1; i < ((long long)20); i++)
    par[i][x] = par[i - 1][par[i - 1][x]];
  for (auto u : e[x])
    if (u != par[0][x]) par[0][u] = x, dis[u] = dis[x] + 1, pre_dfs(u);
  fnsh[x] = _cnt;
}
long long iPar(long long x, long long num) {
  for (int i = 0; i < ((long long)20); i++)
    if ((num & (1 << i))) x = par[i][x];
  return x;
}
long long lca(long long x, long long y) {
  if (dis[x] < dis[y]) swap(x, y);
  x = iPar(x, dis[x] - dis[y]);
  if (x == y) return x;
  for (int i = ((long long)20) - 1; i >= 0; i--)
    if (par[i][x] != par[i][y]) x = par[i][x], y = par[i][y];
  return par[0][x];
}
void shift(long long id) {
  lazy[id * 2] += lazy[id];
  seg[id * 2] += lazy[id];
  lazy[id * 2 + 1] += lazy[id];
  seg[id * 2 + 1] += lazy[id];
  lazy[id] = 0;
}
void build(long long xl = 0, long long xr = n, long long id = 1) {
  if (xl == xr - 1) {
    seg[id] = dis[r_strt[xl]];
    return;
  }
  long long mid = (xl + xr) / 2;
  build(xl, mid, id * 2);
  build(mid, xr, id * 2 + 1);
  seg[id] = max(seg[id * 2], seg[id * 2 + 1]);
}
void update(long long ql, long long qr, long long val, long long xl = 0,
            long long xr = n, long long id = 1) {
  if (qr <= xl || xr <= ql) return;
  if (ql <= xl && xr <= qr) {
    seg[id] += val;
    lazy[id] += val;
    return;
  }
  long long mid = (xl + xr) / 2;
  shift(id);
  update(ql, qr, val, xl, mid, id * 2);
  update(ql, qr, val, mid, xr, id * 2 + 1);
  seg[id] = max(seg[id * 2], seg[id * 2 + 1]);
}
long long query(long long ql, long long qr, long long xl = 0, long long xr = n,
                long long id = 1) {
  if (qr <= xl || xr <= ql) return 0;
  if (ql <= xl && xr <= qr) return seg[id];
  long long mid = (xl + xr) / 2;
  shift(id);
  return max(query(ql, qr, xl, mid, id * 2),
             query(ql, qr, mid, xr, id * 2 + 1));
}
void dfs(long long x) {
  for (auto u : qu[x]) {
    if (u.second < 0)
      ans[-u.second] = max(ans[-u.second], max(query(0, strt[u.first]),
                                               query(fnsh[u.first], n)));
    else
      ans[u.second] = max(ans[u.second], query(strt[u.first], fnsh[u.first]));
  }
  for (auto u : e[x])
    if (u != par[0][x]) {
      update(0, n, 1);
      update(strt[u], fnsh[u], -2);
      dfs(u);
      update(0, n, -1);
      update(strt[u], fnsh[u], +2);
    }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    long long v, u;
    cin >> v >> u;
    e[v].push_back(u);
    e[u].push_back(v);
  }
  pre_dfs(1);
  cin >> m;
  for (int i = 1; i <= m; i++) {
    long long v, u;
    cin >> v >> u;
    long long p = lca(v, u);
    if (dis[v] < dis[u]) swap(v, u);
    long long len = dis[v] + dis[u] - 2 * dis[p];
    if (dis[v] == dis[u])
      qu[v].push_back(
          {iPar(u, (dis[u] - dis[p]) - (len / 2 - (dis[v] - dis[p])) - 1), -i});
    else
      qu[v].push_back({iPar(v, len / 2), i});
    qu[u].push_back(
        {iPar(v, (dis[v] - dis[p]) - (len / 2 - (dis[u] - dis[p])) - 1), -i});
  }
  build();
  dfs(1);
  for (int i = 1; i <= m; i++) cout << ans[i] << "\n";
  return 0;
}
