#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int st[1 << 15 | 5];
pair<int, int> Read() {
  int x, y;
  scanf("%d%d", &x, &y);
  return pair<int, int>(x, y);
}
int n, top, op_top;
int fa[N * 5], S[N * 5];
vector<int> e[N * 5];
pair<int, int> p1[N], p2[N];
pair<int, int> q[N * 5];
int op[N * 10], q1[N * 5];
pair<int, int> LCA(pair<int, int> x, pair<int, int> y) {
  pair<int, int> z(0, 0);
  for (int i = (int)(29); i >= (int)(0); i--)
    if (x.first & y.first & (1 << i)) {
      z.first += 1 << i;
      y.first -= 1 << i;
      x.first -= 1 << i;
    } else if (x.second & y.second & (1 << i)) {
      z.second += 1 << i;
      y.second -= 1 << i;
      x.second -= 1 << i;
    } else {
      if (x.first & (1 << i)) x.first = (1 << i) - 1, x.second = 0;
      if (x.second & (1 << i)) x.second = (1 << i) - 1, x.first = 0;
      if (y.first & (1 << i)) y.first = (1 << i) - 1, y.second = 0;
      if (y.second & (1 << i)) y.second = (1 << i) - 1, y.first = 0;
    }
  return z;
}
pair<int, int> Fa(pair<int, int> x) {
  if (x.first >= 0 && ((x.first - 1) & x.second) == 0)
    return pair<int, int>(x.first - 1, x.second);
  return pair<int, int>(x.first, x.second - 1);
}
bool isFa(pair<int, int> x, pair<int, int> y) { return LCA(x, y) == x; }
bool cmp(pair<int, int> x, pair<int, int> y) {
  if (x == y) return 0;
  int v = (x.first ^ y.first) | (x.second ^ y.second);
  int i = (v >> 15 ? st[v >> 15] + 15 : st[v]);
  int c0 = (x.first >> i) & 1;
  int c1 = (x.second >> i) & 1;
  int c2 = (y.first >> i) & 1;
  int c3 = (y.second >> i) & 1;
  int t1 = (c0 ? 0 : (c1 ? 2 : 1));
  int t2 = (c2 ? 0 : (c3 ? 2 : 1));
  if (t1 != t2) {
    if (t1 == 2) return 0;
    if (t2 == 2) return 1;
    if (t1 == 1) return ((x.second & ((1 << i) - 1)) == 0) ? 1 : 0;
    if (t2 == 1) return ((y.second & ((1 << i) - 1)) == 0) ? 0 : 1;
  }
}
int Idx(pair<int, int> x) {
  return lower_bound(q + 1, q + top + 1, x, cmp) - q;
}
void dfs(int x) {
  for (auto i : e[x]) dfs(i), S[x] += S[i];
  if (S[x]) {
    op[++op_top] = (x == 1 ? 0 : q[fa[x]].first + q[fa[x]].second + 1);
    op[++op_top] = q[x].first + q[x].second + 1;
  }
}
int main() {
  for (int i = (int)(0); i <= (int)(32767); i++)
    for (int j = (int)(0); j <= (int)(14); j++)
      if (i & (1 << j)) st[i] = j;
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n); i++) {
    p1[i] = Read();
    p2[i] = Read();
    q[++top] = p1[i];
    q[++top] = p2[i];
  }
  sort(q + 1, q + top + 1, cmp);
  for (int i = (int)(1); i <= (int)(top - 1); i++)
    q[top + i] = LCA(q[i], q[i + 1]);
  top = top * 2 - 1;
  for (int i = (int)(1); i <= (int)(n); i++) {
    pair<int, int> L = LCA(p1[i], p2[i]);
    if (L != pair<int, int>(0, 0)) q[++top] = Fa(L);
  }
  sort(q + 1, q + top + 1, cmp);
  top = unique(q + 1, q + top + 1) - q - 1;
  int t = 1;
  q1[1] = 1;
  for (int i = (int)(2); i <= (int)(top); i++) {
    for (; top && !isFa(q[q1[t]], q[i]); --t)
      ;
    fa[i] = q1[t];
    e[q1[t]].push_back(i);
    q1[++t] = i;
  }
  for (int i = (int)(1); i <= (int)(n); i++) {
    ++S[Idx(p1[i])];
    ++S[Idx(p2[i])];
    assert(p1[i] == q[Idx(p1[i])]);
    assert(p2[i] == q[Idx(p2[i])]);
    pair<int, int> L = LCA(p1[i], p2[i]);
    --S[Idx(L)];
    if (L != pair<int, int>(0, 0)) --S[Idx(Fa(L))];
  }
  dfs(1);
  int ans = 0;
  sort(op + 1, op + op_top + 1);
  t = 1;
  for (int i = (int)(2); i <= (int)(op_top); i++)
    if (t && op[i] == op[t])
      --t;
    else
      op[++t] = op[i];
  cout << t - (t && op[1] == 0) << endl;
}
