#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int len(pair<int, int> xy) { return xy.first + xy.second; }
pair<int, int> jump(pair<int, int> xy, int len) {
  if (len == 0) return xy;
  auto [x, y] = xy;
  if (len > x + y) return {0, 0};
  int bit = 31 - __builtin_clz(len);
  int cur = x + y;
  int take = cur & ((1 << bit) - 1);
  assert(take <= len);
  x &= ~take;
  y &= ~take;
  len -= take;
  while (len > 0) {
    int bit = __builtin_ctz(x + y);
    int take = min(1 << bit, len);
    if ((x >> bit) & 1)
      x -= take;
    else
      y -= take;
    len -= take;
  }
  return {x, y};
}
pair<int, int> lca(pair<int, int> u, pair<int, int> v) {
  int lu = len(u), lv = len(v);
  if (lu > lv) {
    swap(lu, lv);
    swap(u, v);
  }
  v = jump(v, lv - lu);
  if (u == v) return u;
  int lo = -1, hi = len(u);
  while (lo + 1 < hi) {
    auto mi = (lo + hi) / 2;
    if (jump(u, mi) != jump(v, mi))
      lo = mi;
    else
      hi = mi;
  }
  return jump(u, hi);
}
bool cmp(pair<int, int> u, pair<int, int> v) {
  if (u == v) return false;
  bool swp = false;
  int lu = len(u), lv = len(v);
  if (lu > lv) {
    swap(lu, lv);
    swap(u, v);
    swp = true;
  }
  v = jump(v, lv - lu);
  if (u == v) return true ^ swp;
  return (u > v) ^ swp;
}
bool ancestor(pair<int, int> u, pair<int, int> v) {
  int lu = len(u), lv = len(v);
  if (lv < lu) return false;
  v = jump(v, lv - lu);
  return u == v;
}
vector<int> change;
void add(int l, int r) {
  change.push_back(l);
  change.push_back(r);
}
void simplify() {
  sort((change).begin(), (change).end());
  vector<int> st;
  for (auto x : change) {
    if (!st.empty() && st.back() == x)
      st.pop_back();
    else
      st.push_back(x);
  }
  change = st;
}
using event = pair<pair<int, int>, int>;
vector<event> evt;
void compress(vector<event> &evt) {
  vector<event> nevt;
  for (int i = 0; i < ((int)(evt).size());) {
    int j = i + 1;
    while (j < ((int)(evt).size()) && evt[j].first == evt[i].first) ++j;
    int val = 0;
    for (int k = (int)(i); k < ((int)j); k++) val += evt[k].second;
    nevt.emplace_back(evt[i].first, val);
    i = j;
  }
  evt = nevt;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int m;
  cin >> m;
  while (m--) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    pair<int, int> u(x1, y1), v(x2, y2);
    pair<int, int> w = lca(u, v);
    evt.emplace_back(u, +1);
    evt.emplace_back(v, +1);
    evt.emplace_back(w, -1);
    if (len(w)) {
      w = jump(w, 1);
      evt.emplace_back(w, -1);
    }
  }
  auto evt_cmp = [](const event &a, const event &b) {
    return cmp(a.first, b.first);
  };
  sort((evt).begin(), (evt).end(), evt_cmp), compress(evt);
  int sz = ((int)(evt).size());
  for (int i = 0; i < (int)(sz - 1); i++)
    evt.emplace_back(lca(evt[i].first, evt[i + 1].first), 0);
  sort((evt).begin(), (evt).end(), evt_cmp);
  compress(evt);
  evt.emplace_back(make_pair(-1, -1), 0);
  vector<event> stack;
  for (auto &uv : evt) {
    auto [u, val] = uv;
    while (!stack.empty() && !ancestor(stack.back().first, u)) {
      auto [v, val_v] = stack.back();
      stack.pop_back();
      if (val_v > 0) {
        add(len(v), len(v) + 1);
        if (!stack.empty()) {
          add(len(stack.back().first) + 1, len(v));
          stack.back().second += val_v;
        }
      }
    }
    stack.push_back(uv);
  }
  if (!stack.empty()) {
  }
  simplify();
  int ans = ((int)(change).size());
  if (ans > 0 && change[0] == 0) --ans;
  cout << ans << endl;
  return 0;
}
