1. 

/**
* FWP, Ausgew¤hlte Probleme aus dem ACM Programming Contest
* Problem: 11665 - Chinese Ink
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=78&page=show_problem&problem=2712
*
*
* Method : Point in Polygon(Ray method)
* Status : Accepted
* Runtime: 0.684
*
* @author Evgeni Pavlidis
* @version 1.0, 09/11/2010
*/

import java.io.*;
import java.util.*;


class Point
{
double x,y;

Point(int x, int y)
{ this.x = x; this.y = y; }

public String toString()
{ return "(" + x + "," + y + ")"; }
}


class Segment
{
Point p1, p2;
Segment(Point a, Point b)
{ p1 = a; p2 = b; }

boolean intersects(Segment o)
{
if(containsPoint(o.p1) || containsPoint(o.p2) ||
o.containsPoint(p1) || o.containsPoint(p2))
return true;

long t1 = crossProduct(p1, p2, o.p1);
long t2 = crossProduct(p1, p2, o.p2);
long t3 = crossProduct(o.p1, o.p2, p1);
long t4 = crossProduct(o.p1, o.p2, p2);

if(t1*t2 < 0 && t3*t4 < 0)
return true;

return false;
}

boolean containsPoint(Point p)
{ return Math.abs(dist(p1,p2) - (dist(p1,p) + dist(p2,p))) < 1e-10; }

static long crossProduct(Point m, Point a, Point b)
{ return (long)((a.x - m.x)*(b.y - m.y) - (b.x - m.x)*(a.y - m.y)); }

static double dist(Point a, Point b)
{ return Math.sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y)); }

public String toString()
{ return "[" + p1 + "<->" + p2 + "]"; }
}



class Polygon
{
int number;
List<Segment> segments = new ArrayList<Segment>();

Polygon(int n)
{ number = n; }


boolean intersects(Polygon o)
{
for(Segment s1: segments)
for(Segment s2: o.segments)
if(s1.intersects(s2))
return true;

for(Segment s: o.segments)
if(containsPoint(s.p1) || containsPoint(s.p2))
return true;

return false;
}

boolean containsPoint(Point p)
{
boolean isInside = false;

for(Segment s: segments)
if(p.y > Math.min(s.p1.y, s.p2.y) && p.y <= Math.max(s.p1.y, s.p2.y))
if((s.p2.x - s.p1.x)*(p.y - s.p1.y) / (s.p2.y - s.p1.y) + s.p1.x> p.x)
isInside = !isInside;

return isInside;
}

public String toString()
{
String result = "Polygon " + number + " \n";
result += "\tSegments: (" + segments + ")\n";

return result;
}
}


class DisjointSets
{
int[] set;
int n;

DisjointSets(int n)
{
set = new int[n];
for(int i = 0; i < n; i++)
set[i] = i;

this.n = n;
}

int find(int x)
{
if (set[x] == x)
return x;

return find(set[x]);
}

void union(int x, int y)
{
int xRoot = find(x);
int yRoot = find(y);
set[xRoot] = yRoot;
}

int size()
{
int result = 0;
for(int i = 0; i < n; i++)
if(set[i] == i)
result++;

return result;
}
}


class Main
{
public static void main(String...args) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n;
String[] inputs;
Set<Polygon> polygons = new HashSet<Polygon>();
DisjointSets sets;

while(true)
{
// init
polygons.clear();

n = Integer.parseInt(br.readLine());
if(n==0)
break;

sets = new DisjointSets(n);

// read input
Point a,b = null;
Segment s;
for(int i = 0; i < n; i++)
{
inputs = br.readLine().split("\\s");
Polygon p = new Polygon(i);

for(int j = 0; j < inputs.length-2; j+=2)
{
a = new Point(Integer.parseInt(inputs[j+0]), Integer.parseInt(inputs[j+1]) );
b = new Point(Integer.parseInt(inputs[j+2]), Integer.parseInt(inputs[j+3]) );
p.segments.add(new Segment(a,b));
}

// close polygon
p.segments.add(new Segment(b, p.segments.get(0).p1));

polygons.add(p);
}

// check
for(Polygon p1: polygons)
for(Polygon p2: polygons)
if(sets.find(p1.number) != sets.find(p2.number))
if(p1.intersects(p2))
sets.union(p1.number, p2.number);

System.out.println(sets.size());
}
}
}