#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 70;
const int INF = 2.1e9;
const int MOD = 1e9 + 7;
int n, m, k;
vector<int> G[maxn];
int pre[maxn], idx[maxn], sz[maxn], dep[maxn], fa[maxn], anc[maxn][20],
    dfs_clock;
void dfs(int u) {
  pre[u] = ++dfs_clock;
  idx[dfs_clock] = u;
  sz[u] = 1;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v != fa[u]) {
      fa[v] = u;
      dep[v] = dep[u] + 1;
      dfs(v);
      sz[u] += sz[v];
    }
  }
}
void preprocess() {
  for (int i = 0; i < n; i++) {
    anc[i][0] = fa[i];
    for (int j = 1; (1 << j) < n; j++) anc[i][j] = -1;
  }
  for (int j = 1; (1 << j) < n; j++) {
    for (int i = 0; i < n; i++) {
      if (anc[i][j - 1] != -1) {
        int a = anc[i][j - 1];
        anc[i][j] = anc[a][j - 1];
      }
    }
  }
}
int lca(int p, int q) {
  if (dep[p] < dep[q]) swap(p, q);
  int log = 0;
  for (; (1 << log) <= dep[p]; log++)
    ;
  log--;
  for (int i = log; i >= 0; i--) {
    if (dep[p] - (1 << i) >= dep[q]) {
      p = anc[p][i];
    }
  }
  if (p == q) return p;
  for (int i = log; i >= 0; i--) {
    if (anc[p][i] != anc[q][i]) {
      p = anc[p][i];
      q = anc[q][i];
    }
  }
  return fa[p];
}
int root[maxn], maxv[100 * maxn], addv[100 * maxn], ls[100 * maxn],
    rs[100 * maxn], tot;
void maintain(int rt, int L, int R) {
  if (L == R)
    maxv[rt] = addv[rt];
  else {
    maxv[rt] = max(maxv[ls[rt]], maxv[rs[rt]]);
    maxv[rt] += addv[rt];
  }
}
void build(int &rt, int L, int R) {
  rt = ++tot;
  if (L == R) {
    addv[rt] = dep[idx[L]];
  } else {
    addv[rt] = 0;
    int M = L + (R - L) / 2;
    build(ls[rt], L, M);
    build(rs[rt], M + 1, R);
  }
  maintain(rt, L, R);
}
int ql, qr, ans;
void update(int &rt, int last, int L, int R) {
  rt = ++tot;
  ls[rt] = ls[last];
  rs[rt] = rs[last];
  addv[rt] = addv[last];
  maxv[rt] = maxv[last];
  if (ql <= L && qr >= R) {
    addv[rt]--;
  } else if (ql > R || qr < L) {
    addv[rt]++;
  } else {
    int M = L + (R - L) / 2;
    update(ls[rt], ls[last], L, M);
    update(rs[rt], rs[last], M + 1, R);
  }
  maintain(rt, L, R);
}
void query1(int rt, int L, int R, int add) {
  if (ql <= L && qr >= R) {
    ans = max(ans, maxv[rt] + add);
  } else {
    int M = L + (R - L) / 2;
    if (ql <= M) query1(ls[rt], L, M, add + addv[rt]);
    if (qr >= M + 1) query1(rs[rt], M + 1, R, add + addv[rt]);
  }
}
void query2(int rt, int L, int R, int add) {
  if (ql <= L && qr >= R) {
    ;
  } else if (ql > R || qr < L) {
    ans = max(ans, maxv[rt] + add);
  } else {
    int M = L + (R - L) / 2;
    query2(ls[rt], L, M, add + addv[rt]);
    query2(rs[rt], M + 1, R, add + addv[rt]);
  }
}
int main() {
  while (cin >> n) {
    for (int i = 0; i < n; i++) G[i].clear();
    for (int i = 0; i < n - 1; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      u--;
      v--;
      G[u].push_back(v);
      G[v].push_back(u);
    }
    int rt = 0;
    dep[rt] = 0;
    fa[rt] = -1;
    dfs_clock = 0;
    dfs(rt);
    preprocess();
    tot = 0;
    build(root[rt], 1, n);
    queue<int> Q;
    Q.push(rt);
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      for (int i = 0; i < G[u].size(); i++) {
        int v = G[u][i];
        if (v != fa[u]) {
          ql = pre[v];
          qr = pre[v] + sz[v] - 1;
          update(root[v], root[u], 1, n);
          Q.push(v);
        }
      }
    }
    cin >> m;
    while (m--) {
      int u, v;
      scanf("%d%d", &u, &v);
      u--;
      v--;
      if (dep[u] < dep[v]) swap(u, v);
      int p = lca(u, v);
      int l = dep[u] + dep[v] - 2 * dep[p];
      l = (l - 1) / 2;
      int log, x = u;
      for (log = 0; (1 << log) <= l; log++)
        ;
      log--;
      for (int i = log; i >= 0; i--)
        if (l >= (1 << i)) {
          x = anc[x][i];
          l -= (1 << i);
        }
      ql = pre[x];
      qr = pre[x] + sz[x] - 1;
      ans = 0;
      query1(root[u], 1, n, 0);
      query2(root[v], 1, n, 0);
      printf("%d\n", ans);
    }
  }
  return 0;
}
