Rubik's Cube
Submissions: 143   Accuracy:

16.09%

  Difficulty: Medium   Marks: 4

Representation of a Rubik's Cube:

Yellow face is Up

Orange face is Front

Green face is Left

Blue face is Right

Red face is Back

White face is Down

Since the center pieces are fixed, any face rotation wont changes the central pieces.

Now lets take a look at the nomenclature of Rubik's Cube moves:

R= clockwise 90∘ rotation of right face.

Ri=anti-clockwise 90∘ rotation of right face.

Similarly rest of the moves are illustrated below:

Now you will be given the description of a scrambled Rubik's Cube, your task is to print the description of cube after N given moves.

For eg, if the given cube is:

 

It will be represented as following:

UP
GWYWYYRWW
FRONT
GGRBORYYY
LEFT
YOWRGOOOB
RIGHT
BGRGBBBOO
BACK
GROWRBBRG
DOWN
RBOYWGWYW

Let's say we apply the following moves to the cube:

B B

The move will rotate back face 180∘ clockwise, now the cube is:

And its description will be:

UP
WYWWYYRWW
FRONT
GGRBORYYY
LEFT
OOWBGOROB
RIGHT
BGOGBRBOY
BACK
GRBBRWORG
DOWN
RBOYWGYWG

Input:

First line of input contains a single integer T denoting the number of test cases.

Each test case starts with 12 lines : first line will represent the face name, second line will represent the face color description, third line face name and so on. (see the example given in problem statement).

Note : faces will always come in the order shown in example above {"UP","FRONT","LEFT","RIGHT","BACK","DOWN"}.

Next line of test case contains a single integer N denoting the number of moves to be applied.

Next line of test case contains N space seperated moves (List of valid moves : R, Ri, L, Li, B, Bi, D, Di, F, Fi, U, Ui) .


Output:

For each test case output 12 lines showing the description of cube as shown in example. 

Note : faces must always come in the order shown in example above ie {"UP","FRONT","LEFT","RIGHT","BACK","DOWN"}.


Constraints:

1<=T<=10

1<=N<=50


Example:

Input:

1
UP
GWYWYYRWW
FRONT
GGRBORYYY
LEFT
YOWRGOOOB
RIGHT
BGRGBBBOO
BACK
GROWRBBRG
DOWN
RBOYWGWYW
2
R R

Output:

UP
GWOWYGRWW
FRONT
GGBBOWYYG
LEFT
YOWRGOOOB
RIGHT
OOBBBGRGB
BACK
YRORRBRRG
DOWN
RBYYWYWYW

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Pranay Pandey
Author: pra1nay7_313


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.