#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
struct st {
  int num, id;
};
bool operator<(const st &a, const st &b) { return a.num > b.num; }
multiset<st> my_set[100050];
struct edge {
  int id;
  edge *next;
};
int ednum;
edge edges[200050];
edge *adj[100050];
int dep[100050], son_dis[100050], fa_dis[100050], max_num[100050],
    father[100050], max_x[100050], rt[25][100050], siz[100050], up[25][100050],
    down[25][100050];
bool vis[100050];
inline void addedge(int a, int b) {
  edge *tmp = &edges[ednum++];
  tmp->id = b;
  tmp->next = adj[a];
  adj[a] = tmp;
}
void dfs(int pos, int deep) {
  dep[pos] = deep;
  siz[pos] = 1;
  int mmax = -1;
  for (edge *it = adj[pos]; it; it = it->next) {
    if (dep[it->id] == 0) {
      father[it->id] = pos;
      rt[0][it->id] = pos;
      dfs(it->id, deep + 1);
      st tmp;
      tmp.id = it->id;
      tmp.num = son_dis[it->id];
      my_set[pos].insert(tmp);
      mmax = max(mmax, son_dis[it->id]);
      son_dis[pos] = max(son_dis[pos], son_dis[it->id] + 1);
      siz[pos] += siz[it->id];
    }
  }
  int num = 0;
  for (edge *it = adj[pos]; it; it = it->next) {
    if (father[it->id] == pos && son_dis[it->id] == mmax) num++;
  }
  max_num[pos] = num;
  max_x[pos] = mmax + 1;
}
void dfs2(int pos) {
  fa_dis[pos] = fa_dis[father[pos]] + 1;
  if (max_num[father[pos]] > 1 || son_dis[pos] + 1 != max_x[father[pos]]) {
    fa_dis[pos] = max(fa_dis[pos], max_x[father[pos]] + 1);
    up[0][pos] = max_x[father[pos]] - dep[father[pos]];
    down[0][pos] = max_x[father[pos]] + dep[father[pos]];
  } else {
    int maxx = -2;
    for (edge *it = adj[father[pos]]; it; it = it->next) {
      if (father[it->id] == father[pos] && (it->id != pos)) {
        maxx = max(maxx, son_dis[it->id]);
      }
    }
    fa_dis[pos] = max(fa_dis[pos], maxx + 2);
    if (maxx == -2) maxx = -1;
    maxx++;
    up[0][pos] = maxx - dep[father[pos]];
    down[0][pos] = maxx + dep[father[pos]];
  }
  for (edge *it = adj[pos]; it; it = it->next) {
    if (father[it->id] == pos) dfs2(it->id);
  }
}
void prelca(int n) {
  up[0][0] = down[0][0] = -inf;
  for (int i = 1; i <= 20; i++) {
    for (int j = 1; j <= n; j++) {
      rt[i][j] = rt[i - 1][j] == -1 ? -1 : rt[i - 1][rt[i - 1][j]];
      up[i][j] = max(up[i - 1][j], up[i - 1][rt[i - 1][j]]);
      down[i][j] = max(down[i - 1][j], down[i - 1][rt[i - 1][j]]);
    }
  }
}
int LCA(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = 0; i < 21; i++) {
    if ((dep[u] - dep[v]) >> i & 1) {
      u = rt[i][u];
    }
  }
  if (u == v) return u;
  for (int i = 19; i >= 0; i--) {
    if (rt[i][u] != rt[i][v]) {
      u = rt[i][u];
      v = rt[i][v];
    }
  }
  return rt[0][u];
}
int jump(int &pos, int num, int tmp[][100050]) {
  int rel = -inf;
  for (int i = 0; i < 21; i++) {
    if (num >> i & 1) {
      rel = max(rel, tmp[i][pos]);
      pos = rt[i][pos];
    }
  }
  return rel;
}
void solve(int a, int b) {
  int r = LCA(a, b);
  if (dep[a] < dep[b]) swap(a, b);
  int maxa, maxb, maxc, maxd, half, v, w, ar, br;
  maxa = maxb = maxc = maxd = 0;
  ar = dep[a] - dep[r];
  br = dep[b] - dep[r];
  v = a;
  w = b;
  half = min((ar + br) / 2, ar - 1);
  maxa = max(son_dis[a], jump(v, half, up) + dep[a]);
  maxb = jump(v, ar - half - 1, down) - dep[r] + br;
  maxc = -inf;
  maxd = fa_dis[r] + min(ar, br);
  if (r != b) {
    maxb = max(maxb, son_dis[b]);
    maxb = max(maxb, jump(w, br - 1, up) + dep[b]);
    set<st>::const_iterator it = my_set[r].begin();
    for (int i = 1; i <= min((int)my_set[r].size(), 3); i++) {
      if (it->id != v && it->id != w) {
        maxc = it->num + 1 + min(dep[a], dep[b]) - dep[r];
        break;
      }
      it++;
    }
  } else {
    set<st>::const_iterator it = my_set[r].begin();
    for (int i = 1; i <= min((int)my_set[r].size(), 2); i++) {
      if (it->id != v) {
        maxc = it->num + 1;
        break;
      }
      it++;
    }
  }
  printf("%d\n", max(max(maxa, maxb), max(maxc, maxd)));
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    addedge(a, b);
    addedge(b, a);
  }
  int m;
  memset(rt, -1, sizeof(rt));
  dfs(1, 1);
  for (edge *it = adj[1]; it; it = it->next) {
    if (father[it->id] == 1) {
      dfs2(it->id);
    }
  }
  prelca(n);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    solve(a, b);
  }
}
