Laser Cutting

No attempts yetTime limit1sMemory limit256 MB

Problem

Jakob's laptop broke, so he decided to build a new one himself. All the electronic parts are bought, and now he needs a case. He wants to cut the case out of plywood on the laser cutter in the university workshop and glue the pieces together. The cutter takes a vector drawing, and Jakob has already drawn one. He does not trust his own drawing and arithmetic, so he asks you to check the drawing.

A drawing is a list of polylines. Every polyline is meant to be a closed polygon that never meets itself, and every segment of every polyline is parallel to the xx axis or to the yy axis. No two polygons may touch or cross. One part may have holes for cables and for other parts, but a hole must not hold a part or another hole. Parts and holes are both drawn as polygons, so this last requirement means that a polygon may lie inside one other polygon, never inside two or more of them.

Read a drawing and report the problem it has, or report that it is correct.

Input

The first line holds the number of test cases tt (t10t \le 10).

Each test case describes one drawing. Its first line holds the number of polylines pp (1p<501 \le p < 50). Every polyline is then given on two lines: the number of points nn (5n505 \le n \le 50), and after that 2n2n integers, the xx and yy coordinate of each point in the order the pen visits them. Every coordinate is an integer between 00 and 10610^6.

Any two neighbouring points of a polyline differ in exactly one coordinate, so every segment is parallel to an axis and no segment has length 00.

Output

Print one line for each test case.

If some polyline is not a closed polygon, or if some polyline meets itself anywhere other than at the point where its first and last point coincide, print INVALID POLYGON.

Otherwise, if two polygons touch or cross, print INTERSECTING POLYGONS.

Otherwise, if some polygon lies inside two or more of the other polygons, print INVALID NESTING.

Otherwise print CORRECT.