#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000 + 10;
struct Node {
  Node *lc, *rc, *p;
  int rev, size, old;
  int left[2], leftA[2], flagLeft[2];
  multiset<int> hash;
  Node() {
    lc = rc = p = 0;
    size = 1;
    rev = 0;
    memset(left, 0, sizeof left);
    memset(leftA, 0, sizeof leftA);
    memset(flagLeft, 0, sizeof flagLeft);
  }
  void update() {
    int i;
    size = 1;
    if (lc) size += lc->size;
    if (rc) size += rc->size;
    for ((i) = (0); (i) != (2); ++(i)) {
      leftA[i] = left[i];
      if (hash.size()) leftA[i] += *hash.rbegin() + 1;
      if (lc) leftA[i] = max(leftA[i], lc->leftA[i]);
      if (rc) leftA[i] = max(leftA[i], rc->leftA[i]);
    }
  }
} tree[MAX];
void revIt(Node* u) {
  if (!u) return;
  u->rev ^= 1;
  swap(u->lc, u->rc);
  swap(u->left[0], u->left[1]);
  swap(u->leftA[0], u->leftA[1]);
  swap(u->flagLeft[0], u->flagLeft[1]);
}
void flagit(Node* u, int i, int b) {
  if (!u) return;
  u->flagLeft[i] += b;
  u->left[i] += b;
  u->leftA[i] += b;
}
void down(Node* u) {
  if (!u) return;
  if (u->rev) {
    revIt(u->lc);
    revIt(u->rc);
    u->rev = 0;
  }
  int i;
  for ((i) = (0); (i) != (2); ++(i))
    if (u->flagLeft[i]) {
      flagit(u->lc, i, u->flagLeft[i]);
      flagit(u->rc, i, u->flagLeft[i]);
      u->flagLeft[i] = 0;
    }
}
void rot(Node* u) {
  Node *fa = u->p, *gfa = fa->p;
  down(fa);
  down(u);
  if (fa->lc == u) {
    if (u->rc) u->rc->p = fa;
    fa->lc = u->rc;
    u->rc = fa;
  } else {
    if (u->lc) u->lc->p = fa;
    fa->rc = u->lc;
    u->lc = fa;
  }
  fa->p = u;
  if (gfa && gfa->lc == fa)
    gfa->lc = u;
  else if (gfa && gfa->rc == fa)
    gfa->rc = u;
  u->old = fa->old;
  u->p = gfa;
  fa->update();
}
bool isRoot(Node* u) { return u->p == 0 || (u->p->lc != u && u->p->rc != u); }
void Splay(Node* u) {
  down(u);
  for (Node* second; !isRoot(u); rot(u))
    if (!isRoot(second = u->p))
      rot((second->lc == u) == (second->p->lc == second) ? second : u);
  u->update();
}
Node* del(Node* u) {
  Splay(u);
  Node* tmp = u->rc;
  if (u->rc) {
    u->rc = 0;
    u->update();
    Splay(tmp);
    flagit(u, 1, -tmp->size);
    flagit(tmp, 0, -u->size);
    u->hash.insert(tmp->leftA[0]);
    tmp->old = tmp->leftA[0];
    down(u);
    u->update();
  }
  return tmp;
}
void insert(Node* u, Node* v) {
  Splay(u);
  Splay(v);
  multiset<int>::iterator it = u->hash.find(v->old);
  u->hash.erase(it);
  flagit(u, 1, v->size);
  flagit(v, 0, u->size);
  down(u);
  down(v);
  u->rc = v;
  u->update();
}
Node* access(Node* u, Node* v = 0) {
  for (; u;) {
    del(u);
    if (v) insert(u, v);
    Splay(u);
    v = u;
    u = u->p;
  }
  return v;
}
void beRoot(Node* u) {
  access(u);
  Splay(u);
  revIt(u);
}
void Link(Node* u, Node* v) {
  beRoot(u);
  beRoot(v);
  access(u);
  access(v);
  Splay(u);
  Splay(v);
  flagit(u, 1, v->size);
  flagit(v, 0, u->size);
  down(u);
  down(v);
  v->p = u;
  u->rc = v;
  u->update();
}
void Cut(Node* u, Node* v) {
  beRoot(u);
  access(v);
  Splay(u);
  u->rc = 0;
  v->p = 0;
  u->update();
  v->update();
  flagit(u, 1, -v->size);
  flagit(v, 0, -u->size);
}
int n;
int Ask(Node* u, Node* v) {
  beRoot(v);
  access(u);
  Splay(v);
  int len = (v->size + 1) / 2;
  Node* tmp = v;
  for (;;) {
    down(tmp);
    int val = (tmp->lc ? tmp->lc->size : 0) + 1;
    if (val == len) break;
    if (len < val)
      tmp = tmp->lc;
    else {
      len -= val;
      tmp = tmp->rc;
    }
  }
  Splay(tmp);
  Node* other = del(tmp);
  for (;; other = other->lc) {
    down(other);
    if (!other->lc) break;
  }
  Splay(other);
  Cut(tmp, other);
  beRoot(u);
  beRoot(v);
  Splay(u);
  Splay(v);
  int ans = max(u->leftA[0], v->leftA[0]);
  Link(tmp, other);
  return ans;
}
int main() {
  int i;
  scanf("%d", &n);
  for ((i) = (1); (i) <= (n - 1); ++(i)) {
    int a, b;
    scanf("%d%d", &a, &b);
    Link(tree + a, tree + b);
  }
  int m;
  scanf("%d", &m);
  while (m--) {
    int a, b;
    scanf("%d%d", &a, &b);
    printf("%d\n", Ask(tree + a, tree + b));
  }
  return 0;
}
