#include <bits/stdc++.h>
using namespace std;
#define TR(i,v)         for(__typeof((v).begin())i=(v).begin();i!=(v).end();++i)
#define DEBUG(x)        cout << #x << " = "; cout << x << endl;
#define SIZE(p)         (int)(p).size()
#define MP(a, b)        make_pair((a), (b))
#define ALL(p)          (p).begin(), (p).end()
#define rep(i, n)       for(int (i)=0; (i)<(int)(n); ++(i))
#define REP(i, a, n)    for(int (i)=(a); (i)<(int)(n); ++(i))
#define FOR(i, a, b)    for(int (i)=(int)(a); (i)<=(int)(b); ++(i))
#define FORD(i, b, a)   for(int (i)=(int)(b); (i)>=(int)(a); --(i))
#define CLR(x, y)       memset((x), (y), sizeof((x)))
typedef long long LL;
typedef pair<int, int> pii;
typedef double NUM;
const double eps = 1e-7;
const double PI = acos(-1);
const double TWO_PI = 2*PI;
inline int dcmp(NUM x)   {
    return abs(x)<eps ? 0 : x<0 ? -1 : 1;
}
inline double zero(double x) {
    return dcmp(x)==0 ? 0 : x;
}
struct Point {
    NUM x, y;
    Point(NUM xx=0, NUM yy=0):    x(xx), y(yy)    {}
    void read() {cin>>x>>y;}
    void print() {cout<<fixed<<setprecision(12)<<x<<" "<<y;}
};
typedef Point Vector;
typedef vector<Point> Polygon;
Vector operator+(Vector A, Vector B)        {return Vector(A.x+B.x, A.y+B.y);}
Vector operator-(Point A, Point B)          {return Vector(A.x-B.x, A.y-B.y);}
Vector operator*(Vector A, NUM p)           {return Vector(A.x*p, A.y*p);}
Vector operator/(Vector A, NUM p)           {return Vector(A.x/p, A.y/p);}
bool operator<(const Point &a, const Point &b) {
    return dcmp(a.x-b.x)<0 || (dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)<0);
}
bool operator == (const Point a, const Point b) {
    return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0;
}
NUM Dot(Vector A, Vector B)                 {return A.x*B.x + A.y*B.y;}
double Length(Vector A)                     {return sqrt(Dot(A,A));}
double Angle(Vector A, Vector B)            {return acos(Dot(A,B)/Length(A)/Length(B));}
NUM Cross(Vector A, Vector B)               {return A.x*B.y - A.y*B.x;}
Point getLineIntersection(Point P, Vector v, Point Q, Vector w,double &tt) {
    Vector u=P-Q;
    double t=Cross(w,u)/Cross(v,w);
    tt=t;
    return P+v*t;
}
bool segmentProperIntersection(Point a1, Point a2, Point b1, Point b2) {
    NUM c1=Cross(a2-a1, b1-a1), c2=Cross(a2-a1, b2-a1);
    NUM c3=Cross(b2-b1, a1-b1), c4=Cross(b2-b1, a2-b1);
    return dcmp(c1)*dcmp(c2) <= 0 && dcmp(c3)*dcmp(c4) <= 0;
}
struct Line {
    Point a,b;
    Line(Point aa,Point bb) {
        a=aa,b=bb;
        if(!(a<b)) swap(a,b);
    }
    friend bool operator== (const Line &x,const Line &y) {
        return x.a == y.a && x.b == y.b;
    }
    friend bool operator< (const Line &x,const Line &y) {
        return MP(x.a,x.b) < MP(y.a,y.b);
    }
};
inline bool isin(Point a,Point b,Point c,Point d) {
    Vector u=b-a,v=d-c;
    if(dcmp(Cross(u,v))==0) {
        return !(a<c) && !(d<b);
    }
    return 0;
}
struct REC {
    Point p[4];
}G[55];
vector<Line> processE(vector<Line> &e) {
    vector<Line> r;
    rep(i,SIZE(e)) if(!(e[i].a==e[i].b))
        r.push_back(e[i]);
    return r;
}
vector<Point> ap;
map<Point,int> M;
int tot;
int getid(Point p) {
    map<Point,int>::iterator f=M.find(p);
    if(f==M.end())  return M[p]=tot++;
    return f->second;
}
vector<int> g[1000000];
bool vis[1000000];
inline void add(int u,int v) {
    g[u].push_back(v), g[v].push_back(u);
}
void dfs(int x) {
    vis[x]=1;
    rep(i,SIZE(g[x])) {
        int y=g[x][i];
        if(!vis[y])
            dfs(y);
    }
}
void convexHull(vector<Point> &p) {
    int n = p.size(), m = 0;        
    static Point ch[1000000];
    for (int i = 0; i < n; i++) {
        while (m > 1 && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) < 0) m--;
        ch[m++] = p[i];
    }    
    int k = m;
    for (int i = n-2; i >= 0; i--) {
        while (m > k && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) < 0) m--;
        ch[m++] = p[i];
    }    
    if (n > 1) m--;
    rep(i,m)	p[i]=ch[i];    
}
int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
  // freopen("C.in", "r", stdin);
  // freopen("C.out", "w", stdout);
#endif
    // ios::sync_with_stdio(false);		cin.tie(0);
    int n;
    vector<Point> V;
    vector<Line> E;
    int cs=0;
    while(scanf("%d", &n)==1 && n) {
    	++cs;    	
        V.clear();  tot=0;  M.clear();E.clear();
        rep(i,1000000) g[i].clear();        
        rep(i,n) {        	
            Point a,b       ;     
            a.read(), b.read();                
            G[i].p[0]=a, G[i].p[1]=Point(a.x,b.y), G[i].p[2]=b, G[i].p[3]=Point(b.x,a.y);
            rep(k,4)
                V.push_back(G[i].p[k]);
            rep(k,4) {
                int u=getid(G[i].p[k]);
                int v=getid(G[i].p[(k+1)%4]);
                g[u].push_back(v);
                g[v].push_back(u);
            }
        }
        int ecc=0;
        rep(i,n) {
        	vector<Point> ip;        	
            rep(j,4) {
            	ip.push_back(G[i].p[j]);
                Point a=G[i].p[j],b=G[i].p[(j+1)%4];                
                rep(ii,n) if(ii!=i)
                rep(jj,4) {
                    Point c=G[ii].p[jj],d=G[ii].p[(jj+1)%4];
                    if(dcmp(Cross(b-a,d-c))==0) continue;
                    if(segmentProperIntersection(a,b,c,d)) {
                        double t;
                        Point it=getLineIntersection(a,b-a,c,d-c,t);                        
                        V.push_back(it);
                        ip.push_back(it);
                    }
                }                
            }
            sort(ALL(ip));	ip.erase(unique(ALL(ip)),ip.end());            
            convexHull(ip);            
            rep(i,SIZE(ip)) {
            	Point &a=ip[i], &b=ip[(i+1)%SIZE(ip)];            	
            	int u=getid(a), v=getid(b);
            	add(u,v);
            	E.push_back(Line(a,b));
            }                             
        }
        assert(tot<1000000);
        sort(ALL(V));
        sort(ALL(E));        
        V.erase(unique(ALL(V)),V.end());
        E.erase(unique(ALL(E)),E.end());
        int vc=SIZE(V);
        int ec=SIZE(E);                                
        int f=-vc+ec+2;
        CLR(vis,0);
        int cc=0;
        rep(i,tot) if(!vis[i]) ++cc,dfs(i);     
        f+=cc-1;        
        printf("%d\n",f);
    }
    return 0;
}