QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 10

#11664. Contour Lines

Statistics

Let us consider a set of polygons with sides parallel to the axes of the coordinate system. Such a set of polygons is called a system of contour lines, if it is possible to order all the polygons of the set, so that the first polygon contains the second polygon in its interior, the second polygon contains the third polygon in its interior etc.

Your task is to check, if a given set of polygons is a system of contour lines.

Task

Write a program, which:

  • reads descriptions of a few sets of polygons,
  • for each set decides, if it is a system of contour lines,
  • writes the result to the standard output.

Input

In the first line there is one natural number $t$ ($1 \le t \le 10$), denoting the number of sets to processed. Following, there are $t$ data sets. The first line of each data set contains one integer $n$ ($1 \le n \le 250$), denoting the number of polygons in this set. Each of the next $n$ lines contains one integer $m_i$ ($4 \le m_i \le 250$, $1 \le i \le n$), denoting the number of vertices of the $i$-th polygon, followed by $m_i$ pairs of integers $x_{i,j}$ and $y_{i,j}$ ($0 \le x_{i,j}, y_{i,j} \le 200\,000$), separated with a single space. These pairs describe coordinates of consecutive vertices of the polygon. The sides of each polygon are parallel to the axes of the coordinate system. Furthermore, no two adjacent sides of any polygon are collinear. The perimeter of any polygon does not contain self-crossings.

Output

The standard output should contain $t$ lines. The $k$-th line should contain one word TAK (i.e. yes in Polish), if the $k$-th set of polygons is a system of contour lines, NIE (i.e. no in Polish) otherwise.

Example

Input

3
3
6 1 1 5 1 5 4 4 4 4 6 1 6
6 0 0 0 7 5 7 5 5 7 5 7 0
4 2 3 3 3 3 4 2 4
3
4 2 2 3 2 3 3 2 3
8 1 1 1 4 3 4 3 6 5 6 5 4 4 4 4 1
4 0 0 6 0 6 5 0 5
3
6 1 1 5 1 5 4 4 4 4 6 1 6
6 0 0 0 7 5 7 5 5 7 5 7 0
4 2 3 4 3 4 4 2 4

Output

TAK
NIE
NIE
problem_11664_1.png

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.