Japanese Writing

Time limit2sMemory limit128 MB

Problem

Michael attended the ACM ICPC World Finals 2007 in Tokyo, Japan, and became fascinated with Japanese writing. He decided to study hieroglyphs, and to check his knowledge he needs a program that verifies the correctness of his writing. The program reads the description of one correct hieroglyph shape together with several of Michael's attempts to reproduce it, and judges each attempt as correct or incorrect.

In this problem a hieroglyph is a collection of strokes, where each stroke is a straight line segment on the Cartesian plane. The order of the strokes does not affect the shape, but the direction of each stroke does. Eight directions are relevant: right, upper-right, up, upper-left, left, lower-left, down, and lower-right.

Two writings represent the same shape if a one-to-one correspondence can be established between their strokes and between all of their stroke endpoints such that the direction of every stroke and the relative position of every pair of endpoints are preserved. Relative positions must be preserved for every pair of endpoints, even for pairs that are not joined by a stroke. However, relative position is considered only with respect to the eight directions listed above.

For example, the figure below shows a hieroglyph similar to the Latin letter A, with 5 endpoints joined by 3 strokes, together with several other correct writings of the same shape:

Note that intersections of strokes do not matter. The next figure shows several incorrect writings of the same shape:

These writings are incorrect for the following reasons:

  • Writing 5 has an extra endpoint, so no one-to-one correspondence between endpoints exists.
  • In writing 6, point d is directly above point a, but it should be to its upper-right.
  • In writing 7, stroke d − e goes in the wrong direction.
  • In writing 8, point c is to the lower-right of point a, but it should be directly to its right.
  • Writing 9 has an extra stroke a − d, so no one-to-one correspondence between strokes exists.

Input

The first line contains a single integer n (2 ≤ n ≤ 20) — the number of writings. It is followed by the descriptions of the n writings.

Each writing starts with a line containing a single integer mᵢ (1 ≤ mᵢ ≤ 100) — the number of strokes in the i-th writing. Each of the next mᵢ lines describes one stroke with four integers xa, ya, xb, yb (−1000 ≤ xa, ya, xb, yb ≤ 1000): (xa, ya) is the start point of the stroke and (xb, yb) is its end point. The start and end of a stroke are always distinct, and any two endpoints are joined by at most one stroke.

Output

For each writing from the 2nd to the n-th, compare its shape with the shape of the first writing. Print n − 1 lines; on the i-th line print CORRECT if the (i + 1)-th writing has the same shape as the first writing, or INCORRECT otherwise.