P8854 [POI 2002 R1] Super Knight

Description

On an infinite chessboard, there is a super knight that can perform various moves. Each move consists of two integers. The first number indicates how many squares it moves up or down, and the second number indicates how many squares it moves left or right. Move the knight to perform this move. (Positive numbers mean moving to the right, and negative numbers mean moving to the left.) For each given super knight, determine whether it can reach every position on the chessboard.

Input Format

The first line contains an integer $K$, the number of test cases. For each test case, the first line contains an integer $N$, the number of moves the super knight can perform. The next $N$ lines each contain two integers $P$ and $Q$, describing one move.

Output Format

Output $K$ lines. If the super knight can reach every position on the chessboard, output ```TAK```, otherwise output ```NIE```.

Explanation/Hint

Constraints: $1 \le K,N \le 100$, $-100 \le P,Q \le 100$. Translated by ChatGPT 5