The Same Game

No attempts yetTime limit1sMemory limit128 MB

Problem

Same is a one player game played on a board with 10 rows and 15 columns. Every square holds one ball colored red (R), green (G), or blue (B). Two balls belong to the same cluster when they have the same color and one can be reached from the other by stepping between adjacent balls of that color, moving up, down, left, or right.

On each turn the player picks a ball whose cluster holds at least two balls and removes every ball of that cluster from the board. The board is then compressed in two steps.

  1. The balls left in each column drop down to fill the empty squares. The order of the balls inside a column stays the same.
  2. If a column becomes empty, the columns to its right slide left as far as they can. The order of the columns stays the same.

For example, picking the ball in the bottom left corner of the board below gives this result.

The goal is to clear the board. The game ends when no ball is left, or when every cluster holds exactly one ball.

Scoring works like this. The player starts at 0 points. Removing a cluster of size mm adds (m2)2(m-2)^2 points. A bonus of 1000 points is added if no ball is left when the game ends.

You suspect that picking the ball with the largest cluster on every turn is a good strategy, and you want to test it by writing a program that plays games that way. When two or more balls give a largest cluster, the program picks the leftmost of them. If several of those are still tied, it picks the bottommost one.

Input

The first line holds a positive integer, the number of games that follow. The starting board of each game is given one row at a time, from the top row down to the bottom row. Each row is 15 characters, each of them "R", "G", or "B", giving the colors of the balls in that row from left to right. A blank line comes before each game.

Output

For each game print the game number, then a blank line, then one line per turn, then the final score.

The game number line has this format.

Game x:

Each turn is printed in this format.

Move x at (r,c): removed b balls of color C, got s points.
  • x is the turn number.
  • (r,c) are the row number and the column number of the chosen ball. Rows are numbered 1 to 10 from the bottom, columns 1 to 15 from the left.
  • b is the number of balls in the removed cluster.
  • C is the color of the removed balls, one of "R", "G", or "B".
  • s is the score for this turn. It never includes the 1000 point bonus, even when the turn clears the board.

The final score is printed in this format.

Final score: s, with b balls remaining.

Here s is the final score including the bonus, and b is the number of balls left on the board. Use the plural forms "balls" and "points" even when the number is 1. Print one blank line between consecutive games.