Dijkstra (Large)

Given a short string of i, j and k repeated X times, decide whether it splits into three nonempty parts that multiply to i, j and k under quaternion rules.

Medium7MathSimulationNo attempts yetTime limit5sMemory limit512 MB

Problem

A shortest path algorithm carries the name of the Dutch computer scientist Edsger Dijkstra. This problem is not about that algorithm.

You lost one point on an algorithms exam for misspelling "Dijkstra": between D and stra you wrote some number of characters, each of them i, j, or k. To get the point back you appeal to the quaternions, a number system extended from the complex numbers whose multiplication follows this table.

×\times11iijjkk
1111iijjkk
iiii1-1kkj-j
jjjjk-k1-1ii
kkkkjji-i1-1

To multiply one quaternion by another, read the cell where the row of the first factor meets the column of the second factor. For example, i×ji \times j is kk, and j×ij \times i is k-k.

Quaternion multiplication is not commutative: there are aa and bb with a×bb×aa \times b \ne b \times a. It is associative: for all aa, bb, cc we have a×(b×c)=(a×b)×ca \times (b \times c) = (a \times b) \times c.

Signs behave as usual. For all aa and bb, (a)×(b)=a×b(-a) \times (-b) = a \times b, and (a)×b=a×(b)=(a×b)(-a) \times b = a \times (-b) = -(a \times b).

You want to show that what you wrote is equivalent to the correct spelling ijk. Cut the string at two positions into three non-empty pieces so that, under quaternion multiplication, the first piece reduces to ii, the middle piece reduces to jj, and the last piece reduces to kk. For example, jij is read as j×i×jj \times i \times j: j×ij \times i is k-k, and k×j-k \times j is ii, so jij reduces to ii. Decide whether such a cut exists.

Input

The first line has the number of test cases TT. Then TT test cases follow, each on two lines. The first line has two space separated integers LL and XX. The second line has a string of LL characters, each of them i, j, or k. The string never contains a sign, a 1, or any other character. The string you evaluate is that string of LL characters repeated XX times. For L=4L = 4, X=3X = 3 and the given string kiij, the string you evaluate is kiijkiijkiij.

Limits

  • 1T1001 \le T \le 100
  • 1L100001 \le L \le 10000
  • 1X10121 \le X \le 10^{12}
  • 1L×X10161 \le L \times X \le 10^{16}

Output

For each test case print one line Case #x: y, where xx is the test case number starting from 1, and yy is YES if the string can be cut into three pieces reducing to ii, jj, and kk in that order, and NO otherwise.

Sample explanation

The five cases of the first sample input work out as follows.

In case 1 the string is too short to be split into three pieces.

In case 2, split the string into i, j, and k.

In case 3 the only split into three pieces is k, j, i, and that split does not meet the condition.

In case 4 the string is jijijijijiji. It splits into jij, which reduces to ii, then iji, which reduces to jj, then jijiji, which reduces to kk.

In case 5 no cut ever produces a piece that reduces to jj or to kk.