This page is still under construction.

Parts of this page are still being built. What you see may change.

Cubing

Time limit1sMemory limit128 MB

Summary
Simulate a sequence of Rubik's cube face turns from a solved state and print the colors on the up face.
Level

Medium6 of 10

Topics
Implementation, Simulation, Matrix, Array
Solved
No attempts yet

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 nn (1≤n≤10001 \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.

Examples1

  1. Example 1

    Input
    4
    1
    L-
    2
    F+ B+
    4
    U- D- L+ R+
    10
    L- U- L+ U- L- U- U- L+ U+ U+
    
    Expected output
    rww
    rww
    rww
    bbb
    www
    ggg
    gwg
    owr
    bwb
    gwo
    www
    rww