import std.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.typecons;

struct R {
    int l, t, r, b;
}

void main() {
    int n;
    while (readf("%d\n", &n), n) {
        int[] ps;
        R[] Rs;
        foreach (i; 0 .. n) {
            int[] p = readln.chomp.split(" ").map!(to!int).array;
            ps ~= p;
            Rs ~= R(p[0], p[1], p[2], p[3]);
        }
        int[int] cmap;
        int[] v = [-1] ~ ps.sort.uniq.array ~ [1000002];
        //v.writeln;
        foreach (int i, x; v) {
            cmap[x] = i;
        }
        int ymax = cmap[1000002],
            xmax = cmap[1000002];
        foreach (ref r; Rs) {
            r.l = cmap[r.l];
            r.t = cmap[r.t];
            r.r = cmap[r.r];
            r.b = cmap[r.b];
        }

        long[][] F = new long[][](ymax, xmax);
        void fillR(in R r, long id) {
            foreach (i; r.b .. r.t) {
                foreach (j; r.l .. r.r) {
                    F[i][j] += id;
                }
            }
        }
        foreach (i, r; Rs) {
            fillR(r, (1L << i));
        }

        //foreach (ref _; F) _.writeln;

        bool[][] used = new bool[][](ymax, xmax);
        void dfs(int y, int x) {
            static const dy = [1, 0, -1, 0],
                         dx = [0, 1, 0, -1];
            used[y][x] = true;
            foreach (i; 0 .. 4) {
                int ny = y + dy[i],
                    nx = x + dx[i];
                if (ny < 0 || ny >= ymax) continue;
                if (nx < 0 || nx >= xmax) continue;
                if (used[ny][nx]) continue;
                if (F[ny][nx] != F[y][x]) continue;
                dfs(ny, nx);
            }
        }

        int c = 0;
        foreach (i; 0 .. ymax) {
            foreach (j; 0 .. xmax) {
                if (used[i][j]) continue;
                c++;
                dfs(i, j);
            }
        }

        c.writeln;
    }
}