Contour Lines

No attempts yetTime limit1sMemory limit128 MB

Problem

Consider a set of polygons whose sides are all parallel to the coordinate axes. Such a set is called a system of contour lines if all of its polygons can be ordered so that the first polygon contains the second one in its interior, the second polygon contains the third one in its interior, and so on. In other words, the polygons can be arranged as a strictly nested chain in which each polygon lies entirely inside the previous one.

Given several sets of axis-parallel polygons, decide for each set whether it is a system of contour lines.

Write a program that:

  • reads the descriptions of several sets of polygons,
  • for each set decides whether it is a system of contour lines,
  • writes the answers to standard output.

Input

The first line contains one integer tt (1t101 \le t \le 10), the number of sets to process. The tt sets follow.

The first line of each set contains one integer nn (1n2501 \le n \le 250), the number of polygons in the set. Each of the next nn lines describes one polygon. Such a line begins with one integer mim_i (4mi2504 \le m_i \le 250), the number of vertices of the ii-th polygon, followed by mim_i pairs of integers xijx_{ij} and yijy_{ij} (0xij,yij2000000 \le x_{ij}, y_{ij} \le 200\,000) that give the coordinates of the consecutive vertices of the polygon, separated by single spaces.

Every polygon has sides parallel to the coordinate axes, no two adjacent sides are collinear, and the boundary of each polygon does not cross itself.

Output

Print tt lines. The kk-th line must contain the word TAK (meaning yes) if the kk-th set of polygons is a system of contour lines, and NIE (meaning no) otherwise.

Hint

Nested axis-parallel polygons forming contour lines