#include <bits/stdc++.h>
using namespace std;
long long pwr3[35];
pair<int, int> pre(pair<int, int> node) {
  int x = node.first, y = node.second;
  if (y == 0 || ((x & (-x)) < (y & (-y)) && x > 0)) {
    x--;
  } else {
    y--;
  }
  return make_pair(x, y);
}
int depth(pair<int, int> node) { return node.first + node.second; }
pair<int, int> lca_brute_force(pair<int, int> a, pair<int, int> b) {
  if (depth(a) < depth(b)) swap(a, b);
  int amt = depth(a) - depth(b);
  for (int i = 0; i < amt; i++) {
    a = pre(a);
  }
  while (a != b) {
    a = pre(a);
    b = pre(b);
  }
  return a;
}
pair<int, int> lca(pair<int, int> a, pair<int, int> b) {
  int a_on = a.first | a.second;
  int b_on = b.first | b.second;
  int ansx = 0, ansy = 0;
  for (int i = 30; i >= 0; i--) {
    int bit = (1 << i);
    if (!((a_on | b_on) & bit)) continue;
    if ((a_on & bit) && (b_on & bit)) {
      if ((a.first & bit) && (b.second & bit)) return make_pair(ansx, ansy);
      if ((a.second & bit) && (b.first & bit)) return make_pair(ansx, ansy);
      if (a.first & bit) {
        ansx |= bit;
      } else {
        ansy |= bit;
      }
      continue;
    }
    if (b_on & bit) {
      swap(a, b);
      swap(a_on, b_on);
    }
    bool postswap = false;
    if (a.second & bit) {
      swap(a.first, a.second);
      swap(b.first, b.second);
      swap(ansx, ansy);
      postswap = true;
    }
    int j;
    for (j = i - 1; j >= 0; j--) {
      if (b.second & (1 << j)) break;
    }
    ansx |= (~((1 << (j + 1)) - 1)) & ((1 << (i + 1)) - 1) & b.first;
    if (postswap) swap(ansx, ansy);
    return make_pair(ansx, ansy);
  }
  return make_pair(ansx, ansy);
}
long long dfs_order(pair<int, int> node, int level) {
  if (node.first == 0 && node.second == 0) return 0;
  if (node.first > node.second) {
    return dfs_order(make_pair(node.second, node.first), level) +
           (pwr3[level] - 1LL) / 2LL;
  }
  if (node.first == 0) return node.second;
  if (node.second & (1 << (level - 1)))
    return dfs_order(make_pair(node.first, node.second - (1 << (level - 1))),
                     level - 1) +
           (1LL << (level - 1));
  return dfs_order(node, level - 1) + pwr3[level - 1];
}
map<pair<int, int>, long long> dfsorder;
bool cmp(pair<int, int> a, pair<int, int> b) {
  if (!dfsorder.count(a)) dfsorder[a] = dfs_order(a, 30);
  if (!dfsorder.count(b)) dfsorder[b] = dfs_order(b, 30);
  return dfsorder[a] < dfsorder[b];
}
int m;
pair<int, int> nodes[200005];
pair<int, int> onodes[200005];
pair<int, int> stk[300005];
int stktop = 0;
map<pair<int, int>, vector<pair<int, int> > > tree;
map<pair<int, int>, int> off;
map<pair<int, int>, int> islca;
set<int> flips;
int ans = 0;
void flip(int val) {
  if (val < 0) return;
  if (flips.count(val)) {
    ans--;
    flips.erase(val);
  } else {
    ans++;
    flips.insert(val);
  }
}
int dfs(pair<int, int> node) {
  int toff = off[node];
  for (int i = 0; i < tree[node].size(); i++) {
    int offv = dfs(tree[node][i]);
    if (offv > 0) {
      flip(depth(tree[node][i]));
      flip(depth(node));
    }
    toff += offv;
  }
  if (islca[node] && !toff) {
    flip(depth(node));
    flip(depth(node) - 1);
  }
  return toff;
}
int main() {
  pwr3[0] = 1;
  for (int i = 1; i <= 30; i++) pwr3[i] = 3LL * pwr3[i - 1];
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &(nodes[2 * i - 1].first), &(nodes[2 * i - 1].second),
          &(nodes[2 * i].first), &(nodes[2 * i].second));
  }
  for (int i = 1; i <= 2 * m; i++) onodes[i] = nodes[i];
  sort(nodes + 1, nodes + 2 * m + 1, cmp);
  for (int i = 1; i <= 2 * m; i++) {
    if (nodes[i] == nodes[i - 1]) continue;
    pair<int, int> lcanode = lca(nodes[i], stk[stktop]);
    while (depth(stk[stktop]) > depth(lcanode)) {
      if (depth(stk[stktop - 1]) < depth(lcanode)) {
        tree[lcanode].push_back(stk[stktop]);
      } else {
        tree[stk[stktop - 1]].push_back(stk[stktop]);
      }
      stktop--;
    }
    if (stk[stktop] != lcanode) {
      stktop++;
      stk[stktop] = lcanode;
    }
    stktop++;
    stk[stktop] = nodes[i];
  }
  while (stktop) {
    tree[stk[stktop - 1]].push_back(stk[stktop]);
    stktop--;
  }
  for (int i = 1; i <= m; i++) {
    pair<int, int> lcanode = lca(onodes[i * 2 - 1], onodes[i * 2]);
    off[onodes[i * 2 - 1]]++;
    off[onodes[i * 2]]++;
    off[lcanode] -= 2;
    islca[lcanode]++;
  }
  dfs(make_pair(0, 0));
  printf("%d", ans);
  return 0;
}
