#include <bits/stdc++.h>
using namespace std;
const int maxn = 400010;
int m, ans, tag[maxn], chk[maxn];
vector<int> G[maxn];
struct P {
  int x, y;
  int dep() { return x + y; }
  bool operator<(const P &o) const { return x ^ o.x ? x < o.x : y < o.y; }
  bool operator==(const P &o) const { return x == o.x && y == o.y; }
  P fa() {
    if (!y || x && (x & -x) < (y & -y)) return (P){x - 1, y};
    return (P){x, y - 1};
  }
  P top() {
    if (!x || !y) return (P){0, 0};
    if ((x & -x) > (y & -y)) return (P){x, y - (y & ((x & -x) - 1))};
    return (P){x - (x & ((y & -y) - 1)), y};
  }
};
bool same(P a, P b) { return a.top() == b.top() && (a.x == b.x || a.y == b.y); }
vector<P> V;
vector<pair<P, P>> chain;
map<P, int> mp;
int main() {
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    P p1, p2;
    scanf("%d %d %d %d", &p1.x, &p1.y, &p2.x, &p2.y);
    V.push_back(p1), V.push_back(p2);
    chain.emplace_back(p1, p2);
  }
  sort(V.begin(), V.end(), [&](P a, P b) {
    P _a = a, _b = b;
    while (!same(a, b)) {
      if (a.top().dep() > b.top().dep())
        a = a.top();
      else
        b = b.top();
    }
    P l = a.dep() < b.dep() ? a : b;
    if (_b == l) return false;
    if (_a == l) return true;
    return a.y ^ b.y ? a.y > b.y : a.x < b.x;
  });
  V.resize(unique(V.begin(), V.end()) - V.begin());
  for (int i = 0; i < V.size(); i++) {
    mp[V[i]] = i;
  }
  auto lca = [&](P a, P b) {
    while (!same(a, b)) {
      if (a.top().dep() > b.top().dep())
        a = a.top();
      else
        b = b.top();
    }
    return a.dep() < b.dep() ? a : b;
  };
  auto build = [&]() {
    vector<int> st = {0};
    for (int i = 1, _ = V.size(); i < _; i++) {
      P l = lca(V[i], V[st.back()]);
      if (!mp.count(l)) mp[l] = V.size(), V.push_back(l);
      int id = mp[l];
      while (st.size() > 1 && V[id].dep() < V[st[st.size() - 2]].dep()) {
        G[st[st.size() - 2]].push_back(st.back()), st.pop_back();
      }
      if (!st.empty() && V[id].dep() < V[st.back()].dep()) {
        G[id].push_back(st.back()), st.pop_back();
        if (st.empty() || id ^ st.back()) st.push_back(id);
      }
      st.push_back(i);
    }
    while (st.size() > 1) {
      G[st[st.size() - 2]].push_back(st.back()), st.pop_back();
    }
    return st[0];
  };
  int rt = build();
  for (auto e : chain) {
    int u = mp[e.first], v = mp[e.second], l = mp[lca(V[u], V[v])];
    tag[u]++, tag[v]++, tag[l] -= 2, chk[l] = 1;
  }
  map<int, bool> diff;
  function<void(int, int)> dfs = [&](int v, int fa) {
    for (int u : G[v]) {
      dfs(u, v), tag[v] += tag[u];
    }
    if (tag[v]) {
      diff[V[fa].dep() + 1] ^= 1, diff[V[v].dep() + 1] ^= 1;
    } else if (chk[v]) {
      diff[V[v].dep()] ^= 1, diff[V[v].dep() + 1] ^= 1;
    }
  };
  dfs(rt, -1);
  for (auto p : diff) {
    if (p.second) ans++;
  }
  printf("%d\n", ans - diff[0]);
  return 0;
}
