Let h 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 h sends 1001 to 101110, and it sends the empty string to the empty string. The map h is injective (one to one).
Let hk denote h applied k times, with h0 the identity (h0(w)=w).
Consider the strings hk(0) for k=0,1,2,… The first few are:
0, 1, 10, 101, 10110, 10110101
A string x is a substring of a string y when it appears in y as one contiguous block. You are given integers k1,k2,…,kn. Concatenate
hk1(0)hk2(0)⋯hkn(0)
and decide whether the resulting string is a substring of hm(0) for some m≥0.
The first line holds an integer t (1≤t≤13), the number of test units.
Each test unit uses two lines. The first line holds an integer n (1≤n≤100000). The second line holds n non-negative integers k1,k2,…,kn separated by single spaces. The sum of the integers on that second line is at most 10000000.
Print t lines, one per test unit. For a test unit print TAK if the concatenation hk1(0)⋯hkn(0) is a substring of hm(0) for some m, and NIE otherwise. (TAK and NIE are Polish for yes and no.)
Take k=(1,2): the string is 1 followed by 10, that is 110, and 110 is a substring of h4(0)=10110, so the answer is TAK.
Take k=(2,0): the string is 10 followed by 0, that is 100. The block 00 never occurs in any hm(0), so 100 cannot be a substring and the answer is NIE.