This page is still under construction.

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

Superknight

Time limit3sMemory limit128 MB

Summary
For each knight, decide whether the move vectors generate the full integer lattice of board squares.
Level

Medium7 of 10

Topics
Math, Number theory, Geometry
Solved
No attempts yet

Problem

On an infinite chequered board there is a superknight that can make several kinds of moves. Each kind of move is described by two integers. The first tells how many columns the knight traverses (to the right if the number is positive, to the left if it is negative), and the second tells how many rows it traverses (forward if the number is positive, backward if it is negative).

Write a program that:

  • reads from standard input the data describing several superknights,
  • determines for each superknight whether it can reach any square of the board using only the allowed moves,
  • writes the results to standard output.

Input

The first line of input contains one integer kk, the number of data sets (1≤k≤1001 \le k \le 100). It is followed by kk data sets. The first line of each set contains an integer nn, the number of kinds of moves the superknight can make (1≤n≤1001 \le n \le 100). Each of the next nn lines contains two integers pp and qq separated by a single space (−100≤p,q≤100-100 \le p, q \le 100), describing one kind of move.

Output

The output should consist of kk lines. The ii-th line should contain the word TAK ("yes") if the superknight described by the ii-th data set can reach any square of the board, or the word NIE ("no") otherwise.

Examples3

  1. Example 1

    Input
    2
    3
    1 0
    0 1
    -2 -1
    5
    3 4
    -3 -6
    2 -2
    5 6
    -1 4
    
    Expected output
    TAK
    NIE
    
  2. Example 2

    Input
    1
    2
    1 0
    0 1
    
    Expected output
    TAK
    
  3. Example 3

    Input
    1
    2
    1 2
    2 1
    
    Expected output
    NIE