Words

No attempts yetTime limit1sMemory limit128 MB

Problem

Let hh be a function on binary strings (strings of the digits 0 and 1). It rewrites a string by replacing, simultaneously and independently, every 0 with 1 and every 1 with 10. For instance hh sends 1001 to 101110, and it sends the empty string to the empty string. The map hh is injective (one to one).

Let hkh^k denote hh applied kk times, with h0h^0 the identity (h0(w)=wh^0(w) = w).

Consider the strings hk(0)h^k(\texttt{0}) for k=0,1,2,k = 0, 1, 2, \ldots The first few are:

0, 1, 10, 101, 10110, 10110101

A string xx is a substring of a string yy when it appears in yy as one contiguous block. You are given integers k1,k2,,knk_1, k_2, \ldots, k_n. Concatenate

hk1(0)hk2(0)hkn(0)h^{k_1}(\texttt{0})\, h^{k_2}(\texttt{0}) \cdots h^{k_n}(\texttt{0})

and decide whether the resulting string is a substring of hm(0)h^m(\texttt{0}) for some m0m \ge 0.

Input

The first line holds an integer tt (1t131 \le t \le 13), the number of test units.

Each test unit uses two lines. The first line holds an integer nn (1n1000001 \le n \le 100000). The second line holds nn non-negative integers k1,k2,,knk_1, k_2, \ldots, k_n separated by single spaces. The sum of the integers on that second line is at most 1000000010000000.

Output

Print tt lines, one per test unit. For a test unit print TAK if the concatenation hk1(0)hkn(0)h^{k_1}(\texttt{0}) \cdots h^{k_n}(\texttt{0}) is a substring of hm(0)h^m(\texttt{0}) for some mm, and NIE otherwise. (TAK and NIE are Polish for yes and no.)

Notes

Take k=(1,2)k = (1, 2): the string is 1 followed by 10, that is 110, and 110 is a substring of h4(0)=10110h^4(\texttt{0}) = \texttt{10110}, so the answer is TAK.

Take k=(2,0)k = (2, 0): the string is 10 followed by 0, that is 100. The block 00 never occurs in any hm(0)h^m(\texttt{0}), so 100 cannot be a substring and the answer is NIE.