This page is still under construction.

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

Marbles

Time limit1sMemory limit128 MB

Summary
Decide whether the given multiset of digits can be split into two equal halves with equal digit products.
Level

Medium7 of 10

Topics
Number theory, Math, Combinatorics
Solved
No attempts yet

Problem

Byteted and Bited started a game with marbles. An urn holds an even number of marbles, and every marble carries exactly one digit.

The rules are simple. The two of them take turns drawing one marble each at random from the urn, and the game ends when the urn is empty. The player whose own marbles have the larger product of digits wins. Since they draw one marble at a time in turns, each of them ends up with exactly half of the marbles, and the game is drawn when the two products are equal.

Both boys are ambitious and a draw pleases neither of them. Given the marbles the urn starts with, write a program that decides whether the game can end in a draw.

Input

The first line contains one integer tt (1≤t≤10001 \le t \le 1000), the number of test cases.

Each of the next tt lines contains ten non-negative integers k0,k1,…,k9k_0, k_1, \dots, k_9 (0≤ki≤10150 \le k_i \le 10^{15}), where kik_i is the number of marbles marked with the digit ii. In every test case the sum of the kik_i is even and positive.

Output

Print tt lines, one per test case, in the order of the input. Print TAK if the game can end in a draw and NIE otherwise. TAK is Polish for yes and NIE is Polish for no.

Examples1

  1. Example 1

    Input
    5
    0 1 0 1 1 4 1 0 5 1
    0 1 1 0 3 0 0 0 0 3
    1 1 0 4 0 0 2 0 0 2
    1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000
    0 999999 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000
    
    Expected output
    TAK
    NIE
    NIE
    TAK
    NIE