Locksmith

Time limit1sMemory limit128 MB

Problem

A lock is built from flat pieces that interlock. Every piece is an axis-aligned polygon, so each of its sides is horizontal or vertical. The only way to open the lock is to slide the pieces around on the surface of the door until they come apart.

You may slide one piece at a time in any direction. While a piece moves, it may never occupy a region of positive area together with another piece. Boundaries that touch do not overlap, so contact is allowed. Rotating a piece is not allowed.

A piece is separable if some sequence of slides reaches an arrangement in which you can draw a straight line between that piece and the rest of the lock. Drawing such a line means the piece lies on one side of it and every other piece lies on the other side. The sequence is not limited to the piece you want to free. You may move another piece out of the way first and take the target piece out afterwards.

Given an arrangement of a lock, count the separable pieces. Judge each piece on its own, starting from the given arrangement.

Input

The input holds several test cases. The first line of a test case has the number of pieces $N$ in the lock. Each of the next $N$ lines describes one piece in this format:

c x1 y1 ... xc yc

$c$ is the number of vertices of the piece, and $(x_i, y_i)$ are the vertex coordinates in clockwise order. Every side of a piece is horizontal or vertical, and the two directions alternate. No two pieces occupy a region of positive area together. A test case has either 2 or 3 pieces, and the pieces of one test case have at most 30 vertices in total. All coordinates are integers between 0 and 1000 inclusive.

A test case with 0 pieces ends the input and is not processed.

Output

For each test case, print the number of separable pieces on one line.