RATS sequence

Simulate up to 60 RATS steps per data set and report the first creeper term, the first repeated term, or the last term.

Medium4SimulationStringHash mapNo attempts yetTime limit1sMemory limit256 MB

Problem

The RATS function, short for reverse add then sort, takes one decimal integer and returns a decimal integer whose digits run from the smallest to the largest.

The value is computed in three steps.

  1. Reverse the digits of the input value.
  2. Add the reversed value to the input value.
  3. Sort the digits of the sum into increasing order and drop any leading zeros.
RATS(12334444): 12334444 + 44443321 = 56777765 -> 55667777
RATS(44556): 44556 + 65544 = 110100 -> 111

This problem deals with sequences whose first value is arbitrary and whose every later value is the RATS of the value before it. Here are two examples.

12334444, 55667777, 123334444, 556667777, 1233334444, 5566667777, ...
123, 444, 888, 1677, 3489, 12333, 44556, 111, 222, 444, 888, ...

The first sequence is called the creeper. It provably grows without bound in that regular pattern. A term belongs to the creeper when it reads 12, then aa copies of the digit 3, then 4444, or when it reads 55, then aa copies of the digit 6, then 7777, where a2a \ge 2. The second sequence falls into a cycle, and its tenth term is the first one that repeats an earlier value. Every RATS sequence is conjectured to either reach the creeper and grow without bound or cycle like the second sequence.

Given the starting value, compute the first MM terms of a RATS sequence. Also decide whether the sequence repeats a value inside those MM terms, or enters the creeper inside those MM terms.

Input

The first line contains the number of data sets PP (1P100001 \le P \le 10000). Each data set is independent and is processed the same way.

Each of the next PP lines holds one data set. A line contains the data set number KK, a single space, the number of terms to compute MM (1M601 \le M \le 60), a single space, and the starting value of the RATS sequence. The starting value counts as one term. It is a decimal integer whose digits never decrease from left to right, with at most 40 digits. Later terms may be longer.

Output

Print one line per data set. Give the first term index 1 and inspect the terms in order up to term MM.

If one of the first MM terms belongs to the creeper, print the data set number, a space, the upper case letter C, a space, and the index of the first term that belongs to the creeper.

Otherwise, if one of the first MM terms has the same value as an earlier term of the same sequence, print the data set number, a space, the upper case letter R, a space, and the index of that first repeated term.

Otherwise, print the data set number, a space, and the MMth term.