QOJ.ac

QOJ

Time Limit: 0.1 s Memory Limit: 128 MB Total points: 100

#584. Pebbles

统计

Johny and Margaret are playing "pebbles". Initially there is a certain number of pebbles on a table, grouped in n piles. The piles are next to each other, forming a single row. The arrangement of stones satisfies an additional property that each pile consists of at least as many pebbles as the one to the left (with the obvious exception of the leftmost pile). The players alternately remove any number of pebbles from a single pile of their choice. They have to take care, though, not to make any pile smaller than the one left to it. In other words, the piles have to satisfy the initial property after the move as well. When one of the players cannot make a move (i.e. before his move there are no more pebbles on the table), he loses. Johny always starts, to compensate for Margaret's mastery in this game.

In fact Margaret is so good that she always makes the best move, and wins the game whenever she has a chance. Therefore Johny asks your help - he would like to know if he stands a chance of beating Margaret with a particular initial arrangement. Write a programme that determines answers to Johny's inquiries.

Input

In the first line of the standard input there is a single integer $u$ ($1 ≤ u ≤ 10$) denoting the number of initial pebble arrangements to analyse. The following $2u$ lines contain descriptions of these arrangements; each one takes exactly two lines.

The first line of each description contains a single integer $n$, $1 ≤ n ≤ 1\,000$ - the number of piles. The second line of description holds $n$ non-negative integers ai separated by single spaces and denoting the numbers of pebbles in successive piles, left to right. These numbers satisfy the following inequality $a_1 ≤ a2_ ≤ … ≤ a_n$. The total number of pebbles in any arrangement does not exceed 10,000.

Output

Precisely u lines should be printed out on the standard output. The $i$-th of these lines (for $1 ≤ i ≤ u$) should hold the word TAK (yes in Polish), if Johny can win starting with the $i$-th initial arrangement given in the input, or the word NIE (no in Polish), if Johny is bound to lose that game, assuming optimal play of Margaret.

Example

Input

2
2
2 2
3
1 2 4
problem_584_1.gif

Output

NIE
TAK
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.