#include <bits/stdc++.h>
using namespace std;
struct type {
  int x, y, fx, fy;
} b[100001][2], c[200001], d[400001], A[400001], D[400001], Lca;
int p[30], a[400001][3], ls[400001], fa[400001], f[400001], g[400001],
    dp[400001];
int T, n, N, i, j, k, l, t, len, tot, mn, rt, ans;
map<pair<int, int>, int> mp;
map<int, int> mp2;
void look() {
  for (i = 0; i <= 50; i++) {
    for (j = 0; j <= 50; j++) cout << ((i & j) == 0);
    cout << endl;
  }
}
void swap(type &a, type &b) {
  type c = a;
  a = b;
  b = c;
}
void New(int x, int y) {
  ++len;
  a[len][0] = y;
  a[len][1] = ls[x];
  ls[x] = len;
}
type lca(type a, type b) {
  int i, j, x = 0, y = 0, X1, Y1, X2, Y2, s1, s2;
  for (i = 29; i >= 0; i--) {
    X1 = (a.x & p[i]) > 0, Y1 = (a.y & p[i]) > 0;
    X2 = (b.x & p[i]) > 0, Y2 = (b.y & p[i]) > 0;
    if (X1)
      s1 = 1;
    else if (!Y1)
      s1 = 2;
    else
      s1 = 3;
    if (X2)
      s2 = 1;
    else if (!Y2)
      s2 = 2;
    else
      s2 = 3;
    if (s1 > s2) j = s1, s1 = s2, s2 = j, swap(a, b);
    if (s1 == 1 && s2 == 1)
      x += p[i], a.x -= p[i], b.x -= p[i];
    else if (s1 == 3 && s2 == 3)
      y += p[i], a.y -= p[i], b.y -= p[i];
    else {
      if (s1 == 1) a.x = p[i] - 1, a.y = 0;
      if (s2 == 3) b.y = p[i] - 1, b.x = 0;
    }
  }
  return type{x, y};
}
bool cmp(type a, type b) {
  type Lca = lca(a, b);
  int i, X1, Y1, X2, Y2, s1, s2;
  if (a.x == b.x && a.y == b.y) return 0;
  if (Lca.x == a.x && Lca.y == a.y) return 1;
  if (Lca.x == b.x && Lca.y == b.y) return 0;
  for (i = 29; i >= 0; i--) {
    X1 = (a.x & p[i]) > 0, Y1 = (a.y & p[i]) > 0;
    X2 = (b.x & p[i]) > 0, Y2 = (b.y & p[i]) > 0;
    if (X1)
      s1 = 1;
    else if (!Y1)
      s1 = 2;
    else
      s1 = 3;
    if (X2)
      s2 = 1;
    else if (!Y2)
      s2 = 2;
    else
      s2 = 3;
    if (s1 != s2) return s1 < s2;
    if (s1 == 1 && s2 == 1) a.x -= p[i], b.x -= p[i];
    if (s1 == 3 && s2 == 3) a.y -= p[i], b.y -= p[i];
  }
  return 0;
}
void build() {
  type Lca, s;
  sort(c + 1, c + N + 1, cmp);
  t = 1, d[1] = c[1];
  for (i = 2; i <= N; i++) {
    Lca = lca(d[t], c[i]), l = 0;
    while (t && Lca.x + Lca.y < d[t].x + d[t].y) D[++l] = d[t--];
    if (l) {
      for (j = 1; j <= l - 1; j++) D[j].fx = D[j + 1].x, D[j].fy = D[j + 1].y;
      D[l].fx = Lca.x, D[l].fy = Lca.y;
      while (l) A[++tot] = D[l--];
    }
    if (!t || Lca.x + Lca.y > d[t].x + d[t].y) d[++t] = Lca;
    if (Lca.x + Lca.y < c[i].x + c[i].y) d[++t] = c[i];
  }
  if (t) {
    for (j = t; j >= 1; j--) d[j].fx = d[j - 1].x, d[j].fy = d[j - 1].y;
    while (t) A[++tot] = d[t--];
  }
  mn = 2000000000;
  for (i = 1; i <= tot; i++)
    mp[pair<int, int>(A[i].x, A[i].y)] = i,
                              mn =
                                  (mn < A[i].x + A[i].y ? mn : A[i].x + A[i].y);
  for (i = 1; i <= tot; i++)
    if (A[i].x + A[i].y > mn) {
      j = mp[pair<int, int>(A[i].x, A[i].y)];
      k = mp[pair<int, int>(A[i].fx, A[i].fy)];
      New(k, j);
    } else
      rt = i;
}
void change(int x, int y) {
  int s, s2;
  --x;
  if (x >= 0) s = mp2[x], s2 = s ^ 1, ans += s2 - s, mp2[x] = s2;
  s = mp2[y], s2 = s ^ 1, ans += s2 - s, mp2[y] = s2;
}
void Dfs(int Fa, int t) {
  int i;
  dp[t] = A[t].x + A[t].y, fa[t] = Fa;
  for (i = ls[t]; i; i = a[i][1])
    if (a[i][0] != Fa) Dfs(t, a[i][0]);
}
void dfs(int Fa, int t) {
  int i;
  for (i = ls[t]; i; i = a[i][1])
    if (a[i][0] != Fa) {
      dfs(t, a[i][0]), f[t] += f[a[i][0]], g[t] += g[a[i][0]];
      if (g[a[i][0]] && dp[t] + 1 < dp[a[i][0]])
        change(dp[t] + 1, dp[a[i][0]] - 1);
    }
  if (f[t]) change(dp[t], dp[t]);
}
int main() {
  p[0] = 1;
  for (i = 1; i <= 29; i++) p[i] = p[i - 1] * 2;
  scanf("%d", &n), N = n * 2;
  for (i = 1; i <= n; i++)
    scanf("%d%d%d%d", &b[i][0].x, &b[i][0].y, &b[i][1].x, &b[i][1].y),
        c[i * 2 - 1] = b[i][0], c[i * 2] = b[i][1];
  build();
  Dfs(0, rt);
  for (i = 1; i <= n; i++) {
    if (b[i][0].x + b[i][0].y > b[i][1].x + b[i][1].y) swap(b[i][0], b[i][1]);
    Lca = lca(b[i][0], b[i][1]);
    if (b[i][0].x == b[i][1].x && b[i][0].y == b[i][1].y) {
      j = mp[pair<int, int>(b[i][0].x, b[i][0].y)];
      ++f[j], --f[fa[j]];
    } else if (b[i][0].x == Lca.x && b[i][0].y == Lca.y) {
      j = mp[pair<int, int>(b[i][0].x, b[i][0].y)];
      k = mp[pair<int, int>(b[i][1].x, b[i][1].y)];
      ++f[k], --f[fa[j]];
      ++g[k], --g[j];
    } else {
      j = mp[pair<int, int>(b[i][0].x, b[i][0].y)];
      k = mp[pair<int, int>(b[i][1].x, b[i][1].y)];
      l = mp[pair<int, int>(Lca.x, Lca.y)];
      ++f[j], ++f[k], --f[l], --f[fa[l]];
      ++g[j], ++g[k], g[l] -= 2;
    }
  }
  dfs(0, rt);
  printf("%d\n", ans);
  fclose(stdin);
  fclose(stdout);
  return 0;
}
