Cubing

No attempts yetTime limit1sMemory limit128 MB

Problem

A Rubik's Cube is a three-dimensional puzzle. A standard Rubik's Cube is made of 3×3×3 smaller cubes. The puzzle is solved when the nine small cubes on each face all show the same color.

Each face of the cube can be turned 90 degrees in either direction. After finishing one turn you may turn another face, and by alternating turns of different faces the colors get scrambled.

In this problem the cube starts fully solved, with the following face colors:

  • Up (U): white
  • Down (D): yellow
  • Front (F): red
  • Back (B): orange
  • Left (L): green
  • Right (R): blue

You are given a sequence of turns. After performing all of them, determine the colors of the top (Up) face.

Input

The first line contains the number of test cases (at most 100). Each test case is given as follows:

  • The first line contains the number of turns $n$ ($1 \le n \le 1000$).
  • The second line contains the turns, separated by spaces. Each turn consists of two characters.
    • The first character is the face that is turned: U (up), D (down), F (front), B (back), L (left), or R (right).
    • The second character is the direction: + means clockwise when looking directly at that face, and - means counterclockwise.

Output

For each test case, print the colors of the top (Up) face over three lines. The first line contains the row of cells adjacent to the back face, and the second and third lines follow in order toward the front face. Within each line, print the cells from the one adjacent to the left face to the one adjacent to the right face. Use these letters: w for white, y for yellow, r for red, o for orange, g for green, b for blue.