#include <bits/stdc++.h>
using namespace std;
int MAX_LCA = 20;
void deep(int v, const vector<vector<int>>& edges, vector<int>& tin,
          vector<int>& tout, vector<int>& h, vector<vector<int>>& max,
          vector<vector<int>>& p) {
  static int t = 1;
  tin[v] = t++;
  for (int i = 0; i < edges[v].size(); i++) {
    int u = edges[v][i];
    if (tin[u] == 0) {
      h[u] = h[v] + 1;
      deep(u, edges, tin, tout, h, max, p);
      if (max[u][0] + 1 > max[v][0]) {
        max[v][2] = max[v][1];
        max[v][1] = max[v][0];
        max[v][0] = max[u][0] + 1;
      } else if (max[u][0] + 1 > max[v][1]) {
        max[v][2] = max[v][1];
        max[v][1] = max[u][0] + 1;
      } else if (max[u][0] + 1 > max[v][2]) {
        max[v][2] = max[u][0] + 1;
      }
      p[u][0] = v;
    }
  }
  if (edges[v].size() == 1 && p[v][0] != v) {
    max[v][0] = 0;
  }
  tout[v] = t++;
}
int maxOnLine(int u, int hh, bool type, const vector<int>& h,
              const vector<vector<int>>& p, const vector<vector<int>>& up,
              const vector<vector<int>>& down) {
  int ans = 0;
  int v = u;
  for (int i = MAX_LCA - 1; i >= 0; i--) {
    if ((hh & (1 << i)) == 0) continue;
    if (type) {
      ans = std::max(ans, down[v][i] + h[p[v][i]] - (h[u] - hh));
    } else {
      ans = std::max(ans, up[v][i] + h[u] - h[v]);
    }
    v = p[v][i];
  }
  return ans;
}
bool up(int u, int v, const vector<int>& tin, const vector<int>& tout) {
  return tin[u] < tin[v] && tout[v] < tout[u];
}
int lca(int u, int v, const vector<int>& tin, const vector<int>& tout,
        const vector<vector<int>>& p) {
  if (up(u, v, tin, tout)) return u;
  if (up(v, u, tin, tout)) return v;
  for (int i = MAX_LCA - 1; i >= 0; i--) {
    if (!up(p[u][i], v, tin, tout)) u = p[u][i];
  }
  return p[u][0];
}
int get(int u, int h, const vector<vector<int>>& p) {
  for (int i = MAX_LCA - 1; i >= 0; i--) {
    if ((h & (1 << i)) == 0) continue;
    u = p[u][i];
  }
  return u;
}
int get3(int w, int u, int v, const vector<vector<int>>& max) {
  int cnt = 3;
  for (int i = 0; i < 3; i++) {
    if (max[w][i] == max[u][0] + 1 && (cnt & 1) > 0) {
      cnt--;
      continue;
    }
    if (v != w && max[w][i] == max[v][0] + 1 && (cnt & 2) > 0) {
      cnt -= 2;
      continue;
    }
    return max[w][i];
  }
  return 0;
}
int main() {
  int n = 0;
  cin >> n;
  vector<vector<int>> edges(n);
  vector<int> tin(n, 0);
  vector<int> tout(n, 0);
  vector<int> h(n, 0);
  vector<vector<int>> max(n, vector<int>(3, -n - 1));
  vector<vector<int>> p(n, vector<int>(MAX_LCA));
  int u = -1, v = -1;
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    edges[u - 1].push_back(v - 1);
    edges[v - 1].push_back(u - 1);
  }
  deep(0, edges, tin, tout, h, max, p);
  for (int i = 0; i < max.size(); i++) {
    for (int j = 0; j < max[i].size(); j++) {
      max[i][j] = std::max(max[i][j], 0);
    }
  }
  vector<vector<int>> up(n, vector<int>(MAX_LCA));
  vector<vector<int>> down(n, vector<int>(MAX_LCA));
  for (int i = 0; i < n; i++) {
    up[i][0] = down[i][0] =
        max[p[i][0]][0] == max[i][0] + 1 ? max[p[i][0]][1] : max[p[i][0]][0];
    up[i][0]++;
  }
  for (int j = 1; j < MAX_LCA; j++) {
    for (int i = 0; i < n; i++) {
      p[i][j] = p[p[i][j - 1]][j - 1];
      up[i][j] = std::max(up[p[i][j - 1]][j - 1] + h[i] - h[p[i][j - 1]],
                          up[i][j - 1]);
      down[i][j] = std::max(down[p[i][j - 1]][j - 1],
                            down[i][j - 1] + h[p[i][j - 1]] - h[p[i][j]]);
    }
  }
  int m = 0;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    u--;
    v--;
    if (u == v) {
      cout << std::max(max[u][0], maxOnLine(u, h[u], false, h, p, up, down));
    }
    if (h[u] < h[v]) {
      int z = u;
      u = v;
      v = z;
    }
    int w = lca(u, v, tin, tout, p);
    int ans = max[u][0];
    if (v != w) ans = std::max(ans, max[v][0]);
    int lu = u;
    int hu = std::min(h[u] - h[w] - 1, (h[u] + h[v] - 2 * h[w]) / 2);
    ans = std::max(ans, maxOnLine(u, hu, false, h, p, up, down));
    u = get(u, hu, p);
    if (w != v) {
      ans = std::max(ans, maxOnLine(v, h[v] - h[w] - 1, false, h, p, up, down));
    }
    if (h[lu] > h[v] && h[u] != h[w] + 1)
      ans = std::max(ans, maxOnLine(u, h[u] - h[w] - 1, true, h, p, up, down) +
                              1 + h[v] - h[w]);
    u = get(u, h[u] - h[w] - 1, p);
    ans =
        std::max(ans, maxOnLine(w, h[w], false, h, p, up, down) + h[v] - h[w]);
    if (v != w) {
      ans = std::max(ans,
                     get3(w, u, get(v, h[v] - h[w] - 1, p), max) + h[v] - h[w]);
    } else {
      ans = std::max(ans, get3(w, u, v, max));
    }
    cout << ans << endl;
  }
  return 0;
}
