Contour Map
Time limit3sMemory limit128 MB
Given up to 20000 non-crossing convex orthogonal polygons, compute the maximum nesting depth where the outermost level is 1.
Problem
Hallyeohaesang National Park lies off the southern coast of the Korean peninsula and holds a unique marine ecosystem stretching across 120 km. The park is made up of more than 360 islands, each a different size. The beautiful waterways formed by its 69 uninhabited and 30 inhabited islands are praised as jewels of the sea.
Park manager Sang-geun Kim wants to survey the elevation of every island in the park using contour lines. A contour line connects points of equal altitude above sea level and is a convex closed curve.
The contour lines that describe the park's islands never cross one another; each is a simple, convex, closed curve, like an ellipse.
A computer converts a contour map into a digital contour map. On a digital contour map, every contour is a convex orthogonal polygon. An orthogonal polygon is a polygon whose every edge is either horizontal or vertical. An orthogonal polygon is convex when, for any horizontal or vertical line, the intersection of that line with the interior of is empty or a single segment. (This is orthogonal convexity, i.e. convexity along the horizontal and vertical directions, not convexity in the usual sense.)
The outermost contour has level 1. If the contour that immediately encloses a contour has level , then has level .
Given a digital contour map made of contours, write a program that finds the level of the highest contour.
Input
The first line contains the number of test cases .
For each test case, the first line contains the number of contours (). Each of the following lines describes one contour with integers (, ). Here is the number of vertices of the convex orthogonal polygon, and are its vertices listed in counterclockwise order. No two convex orthogonal polygons overlap.
Output
For each test case, print the level of the highest contour on its own line.