This page is still under construction.

Parts of this page are still being built. What you see may change.

City Wall

Time limit1sMemory limit512 MB

Summary
Decide whether every segment of a polygonal city wall is visible from an interior church point without occlusion by other segments.
Level

Hard8 of 10

Topics
Geometry, Sorting
Solved
No attempts yet

Problem

The King of Byteland has lately noticed a sharp drop in the tax revenue collected by his cities. He suspects it is tied to the arrival of dishonest new merchants who most likely slip across the city walls at night to smuggle goods.

The King decides to hire the all-seeing Jacek to climb the church towers each night and watch the city boundaries. Now he wonders whether that is enough: he is not sure that in every city Jacek can see the whole wall from the church tower. Jacek can see all around his head and straight through every building in the city, yet he cannot see a stretch of wall that is hidden behind another stretch of wall. He also cannot see a stretch of wall that lies entirely along his line of sight, because that stretch is then blocked by one of its endpoints (a vertex).

Each city's boundary is a polygon. No city's wall crosses itself, and the church is never on the wall nor outside the city it belongs to.

Input

The first line of standard input contains a single integer mm (1≤m≤101 \le m \le 10), the number of cities. The descriptions of the cities follow.

The first line of each city's description contains three space-separated integers nn, xx, and yy (3≤n≤100 0003 \le n \le 100\,000, −109≤x,y≤109-10^9 \le x, y \le 10^9): the number of vertices of that city's wall and the coordinates of its church. Each of the next nn lines contains two space-separated integers xix_i and yiy_i (−109≤xi,yi≤109-10^9 \le x_i, y_i \le 10^9), the coordinates of the ii-th wall vertex. The vertices are listed in the order they appear along the wall, so every two consecutive vertices, and the last together with the first, are joined by a wall segment. In tests worth 70% of the points in total, n≤3 500n \le 3\,500.

Output

Print exactly mm lines. The ii-th line contains a single word:

  • TAK if the whole wall of the ii-th city is visible from its church tower,
  • NIE otherwise.

Hint

Examples1

  1. Example 1

    Input
    2
    3 2 3
    1 2
    4 2
    1 6
    4 4 -5
    2 -2
    7 -5
    5 -5
    5 -7
    
    Expected output
    TAK
    NIE