#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int up[MAXN][20], dep[MAXN], n, a, b, p[MAXN][20], up2[MAXN][20], f[MAXN],
    l[MAXN], tme, m;
pair<int, pair<int, int> > mx[MAXN][3];
vector<int> v[MAXN];
void dfs(int x, int y) {
  p[x][0] = y;
  dep[x] = dep[y] + 1;
  f[x] = ++tme;
  for (int i = 0; i < v[x].size(); ++i) {
    int z = v[x][i];
    if (z == y) continue;
    dfs(z, x);
    if (mx[z][0].first + 1 > mx[x][0].first) {
      mx[x][2] = mx[x][1];
      mx[x][1] = mx[x][0];
      mx[x][0].first = mx[z][0].first + 1;
      mx[x][0].second = make_pair(f[z], l[z]);
    } else if (mx[z][0].first + 1 > mx[x][1].first) {
      mx[x][2] = mx[x][1];
      mx[x][1].first = mx[z][0].first + 1;
      mx[x][1].second = make_pair(f[z], l[z]);
    } else if (mx[z][0].first + 1 > mx[x][2].first) {
      mx[x][2].first = mx[z][0].first + 1;
      mx[x][2].second = make_pair(f[z], l[z]);
    }
  }
  l[x] = tme;
}
void calc(int x, int y) {
  if (y != 0) {
    up[x][0] =
        (mx[p[x][0]][0].first == mx[x][0].first + 1 ? mx[p[x][0]][1].first
                                                    : mx[p[x][0]][0].first) -
        dep[p[x][0]];
    up2[x][0] =
        (mx[p[x][0]][0].first == mx[x][0].first + 1 ? mx[p[x][0]][1].first
                                                    : mx[p[x][0]][0].first) +
        dep[p[x][0]];
  }
  for (int i = 1; i < 20; ++i) {
    p[x][i] = p[p[x][i - 1]][i - 1];
    up[x][i] = max(up[x][i - 1], up[p[x][i - 1]][i - 1]);
    up2[x][i] = max(up2[x][i - 1], up2[p[x][i - 1]][i - 1]);
  }
  for (int i = 0; i < v[x].size(); ++i)
    if (v[x][i] != y) calc(v[x][i], x);
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 19; i >= 0; --i)
    if (dep[p[x][i]] >= dep[y]) x = p[x][i];
  if (x == y) return x;
  for (int i = 19; i >= 0; --i)
    if (p[x][i] != p[y][i]) {
      x = p[x][i];
      y = p[y][i];
    }
  return p[x][0];
}
bool subt(int x, pair<int, int> r) { return (x >= r.first && x <= r.second); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dep[0] = -1;
  dfs(1, 0);
  calc(1, 0);
  cin >> m;
  int lc, x, y;
  for (int i = 0; i < m; ++i) {
    int ans = 0;
    cin >> a >> b;
    if (dep[a] < dep[b]) swap(a, b);
    lc = lca(a, b);
    ans = mx[a][0].first;
    if (lc != b) ans = max(ans, mx[b][0].first);
    ans = max(ans, dep[b] + up[lc][19]);
    x = b;
    for (int i = 19; i >= 0; --i)
      if (dep[p[x][i]] > dep[lc]) {
        ans = max(ans, dep[b] + up[x][i]);
        x = p[x][i];
      }
    int len = dep[a] + dep[b] - 2 * dep[lc];
    x = a;
    for (int i = 19; i >= 0; --i) {
      if (dep[p[x][i]] > dep[lc] && dep[a] - dep[p[x][i]] <= len / 2) {
        ans = max(ans, dep[a] + up[x][i]);
        x = p[x][i];
      }
    }
    for (int i = 19; i >= 0; --i) {
      if (dep[p[x][i]] > dep[lc]) {
        ans = max(ans, dep[b] + up2[x][i] - 2 * dep[lc]);
        x = p[x][i];
      }
    }
    for (int i = 0; i < 3; ++i) {
      if (subt(f[a], mx[lc][i].second) == 0 &&
          subt(f[b], mx[lc][i].second) == 0)
        ans = max(ans, mx[lc][i].first + dep[b] - dep[lc]);
    }
    cout << ans << '\n';
  }
}
