#include <bits/stdc++.h>
using namespace std;
const int N = 100005, LG = 18;
int n, q, ts, H[N], R[N], st[N], en[N], P[N][LG], Mx[N * 4], Lz[N * 4];
vector<int> Adj[N];
vector<pair<pair<int, int>, int> > Q[N];
void DFS(int v) {
  st[v] = ts++;
  for (int i = 1; i < LG; i++) P[v][i] = P[P[v][i - 1]][i - 1];
  for (int &u : Adj[v])
    if (u != P[v][0]) H[u] = H[v] + 1, P[u][0] = v, DFS(u);
  en[v] = ts;
}
inline int Parent(int v, int k) {
  for (int i = 0; i < LG; i++)
    if ((k >> i) & 1) v = P[v][i];
  return (v);
}
inline int LCA(int v, int u) {
  if (H[v] < H[u]) return (LCA(u, v));
  v = Parent(v, H[v] - H[u]);
  if (v == u) return (v);
  for (int i = LG - 1; ~i; i--)
    if (P[v][i] != P[u][i]) v = P[v][i], u = P[u][i];
  return (P[v][0]);
}
inline void Shift(int id) {
  Lz[(id << 1)] += Lz[id];
  Mx[(id << 1)] += Lz[id];
  Lz[((id << 1) ^ 1)] += Lz[id];
  Mx[((id << 1) ^ 1)] += Lz[id];
  Lz[id] = 0;
}
void Add(int le, int ri, int val, int id = 1, int l = 0, int r = n) {
  if (ri <= l || r <= le) return;
  if (le <= l && r <= ri) {
    Lz[id] += val;
    Mx[id] += val;
    return;
  }
  Shift(id);
  Add(le, ri, val, (id << 1), l, (l + r >> 1));
  Add(le, ri, val, ((id << 1) ^ 1), (l + r >> 1), r);
  Mx[id] = max(Mx[(id << 1)], Mx[((id << 1) ^ 1)]);
}
int GetMax(int le, int ri, int id = 1, int l = 0, int r = n) {
  if (ri <= l || r <= le) return (0);
  if (le <= l && r <= ri) return (Mx[id]);
  Shift(id);
  return (max(GetMax(le, ri, (id << 1), l, (l + r >> 1)),
              GetMax(le, ri, ((id << 1) ^ 1), (l + r >> 1), r)));
}
void DFS2(int v) {
  for (auto &X : Q[v])
    R[X.second] = max(R[X.second], GetMax(X.first.first, X.first.second));
  for (int &u : Adj[v])
    if (u != P[v][0]) {
      Add(st[u], en[u], -2);
      Add(0, n, 1);
      DFS2(u);
      Add(st[u], en[u], 2);
      Add(0, n, -1);
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1, v, u; i < n; i++)
    scanf("%d%d", &v, &u), Adj[v].push_back(u), Adj[u].push_back(v);
  DFS(1);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int v, u;
    scanf("%d%d", &v, &u);
    if (H[v] < H[u]) swap(v, u);
    int lca = LCA(v, u), d = H[v] + H[u] - H[lca] * 2;
    int mid = Parent(v, (d - 1) >> 1);
    Q[v].push_back({{st[mid], en[mid]}, i});
    Q[u].push_back({{0, st[mid]}, i});
    Q[u].push_back({{en[mid], ts}, i});
  }
  for (int i = 1; i <= n; i++) Add(st[i], st[i] + 1, H[i]);
  DFS2(1);
  for (int i = 1; i <= q; i++) printf("%d\n", R[i]);
  return (0);
}
