Marbles in a Circle

No attempts yetTime limit1sMemory limit256 MB

Problem

Colored marbles sit in a circle. Each marble is red, white, or green. Every second all marbles change color at the same time, and a marble's new color depends only on its own color and the color of the marble to its right.

The rules for changing color are:

  • if the marble is white, its new color is the current color of the marble to its right.
  • otherwise, if the marble to its right is white, the marble keeps its color.
  • otherwise, if the marble to its right has a different color, the marble becomes white.
  • otherwise the marble has the same color as the one to its right, and it flips: red becomes green, green becomes red.

You are given a string SS and an integer NN. Read SS as an array of characters of length LL, so the circle holds LL marbles. The character W is a white marble, R is red, and G is green. Marble i+1i+1 is to the right of marble ii, and marble 00 is to the right of marble L1L-1. Determine the state of the circle after NN seconds.

Input

The first line contains TT (T20T \le 20), the number of test cases.

Each of the next TT lines contains a string SS (1S200001 \le |S| \le 20000) and an integer NN (1N10181 \le N \le 10^{18}) separated by a single space. SS consists only of the characters W, R, and G.

Output

For each test case, print one line in the form Case #X: W R G, where XX is the test case number starting from 1, WW is the number of white marbles, RR is the number of red marbles, and GG is the number of green marbles after NN seconds. Separate the four values with a single space.