Color the Map Extreme

Given simple polygons for each country, decide adjacency when borders share a positive-length segment, then find the chromatic number of the adjacency graph.

Hard8GeometryGraphBacktrackingNo attempts yetTime limit8sMemory limit512 MB

Problem

You have just moved to another world and been handed a map of it. The world has several countries. Each country's territory is connected, and the map draws it as a simple polygon in the plane bounded by that country's border segments.

The world is new to you, so you want to paint the countries on the map to tell them apart. Painting two adjacent countries with the same color makes them hard to tell apart, so you want adjacent countries to get different colors. Two countries are adjacent when their borders share at least one segment whose length is strictly greater than 0. Two countries whose borders touch only at points are not adjacent.

You do not have this world's currency, so preparing many colors is hard. What is the smallest number of colors that paints the map so that adjacent countries get different colors?

Input

The input holds several datasets. There are at most 35 datasets.

Each dataset has this format.

n
m1
x1,1 y1,1
:
:
x1,m1 y1,m1
:
:
mn
xn,1 yn,1
:
:
xn,mn yn,mn

The first line of a dataset holds an integer nn (1n351 \le n \le 35), the number of countries in the world.

The rest of the dataset describes the nn polygons that represent the countries. The first line of the ii-th polygon holds an integer mim_i (3mi503 \le m_i \le 50), the number of vertices. The next mim_i lines give the coordinates of the vertices in counter-clockwise order. The jj-th of them holds two integers xi,jx_{i,j} and yi,jy_{i,j} (xi,j,yi,j103|x_{i,j}|, |y_{i,j}| \le 10^3), the coordinates of the jj-th vertex of the ii-th polygon.

You may assume the following.

  • Every polygon has an area greater than 0.
  • Two vertices of the same polygon have distinct coordinates.
  • Two segments of the same polygon have no common point, except that exactly two segments meet at each vertex.
  • Two polygons share no area.

A line holding a single zero ends the input.

Output

For each dataset, print on one line the smallest number of colors that paints the map so that adjacent countries get different colors.