#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int n, m;
vector<int> edge[200000];
vector<int> md[200000];
int par[200000][20];
int down[200000][20];
int up[200000][20];
int depth[200000];
void back(int now, int parent, int dep) {
  int i, j;
  depth[now] = dep;
  par[now][0] = parent;
  if (par[now][0] == -1) par[now][0] = now;
  for (auto e : edge[now]) {
    if (e == parent) continue;
    back(e, now, dep + 1);
    md[now].push_back(md[e][0] + 1);
  }
  sort(md[now].begin(), md[now].end(), greater<int>());
  md[now].resize(3);
}
int getpar(int now, int d) {
  int i;
  for (i = 0; i < 20; i++) {
    if (d & (1 << i)) now = par[now][i];
  }
  return now;
}
int getlca(int x, int y) {
  int i;
  if (depth[x] < depth[y]) swap(x, y);
  for (i = 19; i >= 0; i--) {
    if ((depth[x] - depth[y]) >= (1 << i)) x = par[x][i];
  }
  if (x == y) return x;
  for (i = 19; i >= 0; i--) {
    if (par[x][i] != par[y][i]) x = par[x][i], y = par[y][i];
  }
  return par[x][0];
}
int maxline(int x, int h, int from) {
  int i;
  int maxx = 0;
  int tx = x;
  for (i = 19; i >= 0; i--) {
    if (h & (1 << i)) {
      if (from == 0) {
        if (maxx < depth[tx] - depth[x] + down[x][i])
          maxx = depth[tx] - depth[x] + down[x][i];
      } else {
        if (maxx < h - (depth[tx] - depth[par[x][i]]) + up[x][i])
          maxx = h - (depth[tx] - depth[par[x][i]]) + up[x][i];
      }
      x = par[x][i];
    }
  }
  return maxx;
}
int main() {
  int i, j, k;
  scanf("%d", &n);
  for (i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--, y--;
    edge[x].push_back(y);
    edge[y].push_back(x);
  }
  for (i = 0; i < n; i++) md[i].resize(3);
  back(0, -1, 0);
  for (j = 1; j < 20; j++) {
    for (i = 0; i < n; i++) par[i][j] = par[par[i][j - 1]][j - 1];
  }
  for (i = 0; i < n; i++) {
    if (md[i][0] + 1 == md[par[i][0]][0]) {
      down[i][0] = 1 + md[par[i][0]][1];
      up[i][0] = md[par[i][0]][1];
    } else {
      down[i][0] = md[par[i][0]][0] + 1;
      up[i][0] = md[par[i][0]][0];
    }
  }
  for (j = 1; j < 20; j++) {
    for (i = 0; i < n; i++) {
      down[i][j] = max(down[i][j - 1], down[par[i][j - 1]][j - 1] + depth[i] -
                                           depth[par[i][j - 1]]);
      up[i][j] = max(up[par[i][j - 1]][j - 1],
                     up[i][j - 1] + depth[par[i][j - 1]] - depth[par[i][j]]);
    }
  }
  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--, y--;
    if (depth[x] < depth[y]) swap(x, y);
    int lca = getlca(x, y);
    int mid = getpar(x, (depth[x] + depth[y] - 2 * depth[lca] + 1) / 2);
    int ans = md[x][0];
    ans = max(ans, (depth[x] + depth[y] - 2 * depth[lca]) / 2);
    if (depth[x] - depth[mid] >= 2)
      ans = max(ans, maxline(x, depth[x] - depth[mid] - 1, 0));
    if (depth[y] - depth[lca] >= 2)
      ans = max(ans, maxline(y, depth[y] - depth[lca] - 1, 0));
    ans = max(ans, maxline(lca, depth[lca], 0) + depth[y] - depth[lca]);
    if (lca == y) {
      int lcad = getpar(x, depth[x] - depth[lca] - 1);
      if (md[lcad][0] + 1 == md[lca][0])
        ans = max(ans, md[lca][1]);
      else
        ans = max(ans, md[lca][0]);
    } else {
      ans = max(ans, md[y][0]);
      int xd = getpar(x, depth[x] - depth[lca] - 1);
      int yd = getpar(y, depth[y] - depth[lca] - 1);
      int xy[2] = {md[xd][0] + 1, md[yd][0] + 1};
      sort(xy, xy + 2, greater<int>());
      int idx = 0;
      if (md[lca][idx] == xy[0]) idx++;
      if (md[lca][idx] == xy[1]) idx++;
      ans = max(ans, md[lca][idx] + depth[y] - depth[lca]);
    }
    if (mid != lca) {
      int midd = getpar(x, depth[x] - depth[mid] - 1);
      if (md[midd][0] + 1 == md[mid][0])
        ans = max(ans, md[mid][1] + (depth[x] + depth[y] - 2 * depth[lca]) / 2);
      else
        ans = max(ans, md[mid][0] + (depth[x] + depth[y] - 2 * depth[lca]) / 2);
    }
    if (depth[mid] - depth[lca] >= 2)
      ans = max(ans, maxline(mid, depth[mid] - depth[lca] - 1, 1) + 1 +
                         depth[y] - depth[lca]);
    printf("%d\n", ans);
  }
  return 0;
}
