Programming Problem #6
"Rubik's Cube"

A Rubik's Cube is a 3x3 cube consisting of 27 smaller cubes designed so that any 3x3x1 outer face can be rotated. Initally, each of the nine squares on a face is painted the same color. Unfolded, the cube initially looks like this:
               *----------------*
               | Up (Red)       |
*--------------+----------------+---------------*-------------*
|Left (Orange) | Front (Yellow) | Right (Green) | Back (Blue) |
*--------------+----------------+---------------*-------------*
               | Down (Indigo)  |
               *----------------*
Any possible transformation of the cube can be described in terms of a series of 90-degree clockwise rotations. "Clockwise" means the usual clockwise direction while looking at the face to be rotated.

The input consists of one or more lines. Each line describes a sequence of rotations, each of which is denoted by a face letter (one of U, D, L, R, F, and B). For example, B denotes a 90-degree clockwise rotation of the back face. The letters are consecutive, with no intervening whitespace. For each line of input, start with the cube in the initial configuration shown above, apply the designated sequence of rotations, then output a picture of the up, front and right faces as shown in the example below. Each letter in the picture represents the color of the corresponding square. In a picture, the uppermost face is the "Up" face, the leftmost face is the "Front" face and the rightmost face is the "Right" face.

Input must be read from the file "prob6.in", and output must be written to the file "prob6.out". All output to the screen will be ignored.


Example Input

<BOF>
RUFD
<EOF>

Example Output

         R
      R     R
   O     R     R
      O     R
Y        I        B
   Y           B
Y     G     Y     G
   Y           G
O     G     Y     G
   O           I
      B     I

A version of this problem originally appeared in the 1982 North Central Regionals.

Dr. Eric Shade