#SDNU1584. Rubik's cube Simulator
Rubik's cube Simulator
Description
As we all know, Rubik's cube is a very popular toy around the world. There are some formalized operations and methods in the professional field of Rubik's cube. A normal description of a Rubik's cube indicates that there are six different colors, white, yellow, red, orange, green and blue, pernuting on the six different side of the cube. And the white side is always facing the yellow side, the red side is always facing the orange side, and the green side is always facing the blue side, just like the following pictrue:
http://www.acmicpc.sdnu.edu.cn/uploads/64FABEC1168A349186E6D4175F8A026B.jpg
As the pictrue shows, imagine that you're holding a Rubik's cube in your hand, then the side you're facing is called F(front side), and whose opposite side is called B(behind side). The side at the left of the F side is called L(left side), and whose opposite side is called R(right side). The side at the top of the F side is called U(up side), and whose opposite side is called D(down side).
Then we could define the operations: if there's another person facing a side of the cube, such as the R side, rotating this side 90-degree clockwise is called R operation, and rotating this side 90-degree anticlockwise is called R' operation. As this way, we could also define the F, F', B, B', L, L', U, U', D, D' operations, just let that guy to face the corresponding side and rotate it clockwise or anticlockwise. PS. you are always facing the F side. Here's a picture that could clarify it:
http://www.acmicpc.sdnu.edu.cn/uploads/B0D843B1687F0B725E772FE56E4266C8.jpg
And we could also rotate the total Rubik's cube: as the following picture shows, rotating the whole cube at the blue arrow's direction around the X axis is called X operation, and doing it at the opposite direction is called X' operation. As the same way we can also define the Y, Y', Z, Z' operations.
http://www.acmicpc.sdnu.edu.cn/uploads/8B43AA5BE163E97933B2A549C99A6F3D.png
Now given some integers permuting as an expanded view of a Rubik's cube like shown above in which the integer1, 2, 3, 4, 5, 6 represents the color of white, yellow, red, orange, green and blue. And given a string combined by one or some elements in L, L', R, R', U, U', D, D', F, F', B, B' and X, X', Y, Y', Z, Z'(rotating operations). Please output the F side when all the operations that the string represented has done.
Format
Input
The first line is a integer T(T < 50) indicates the number of cases In each case, there will be an expanded view combined by integers(1~6) like sample showing, and a string(length <= 200) in a single line following.
Output
Output T cases, each case outputs 3 lines and each line outputs 3 integers and each integer following a blankspace like sample showing.
Samples
2
1 1 1 4 4 4 2 2 2
3 3 3 1 1 1 4 4 4
3 3 3 1 1 1 4 4 4
5 5 5
5 5 5
5 5 5
2 2 2
2 2 2
3 3 3
6 6 6
6 6 6
6 6 6
U'
3 3 3 1 1 1 4 4 4
3 3 3 1 1 1 4 4 4
3 3 3 1 1 1 4 4 4
5 5 5
5 5 5
5 5 5
2 2 2
2 2 2
2 2 2
6 6 6
6 6 6
6 6 6
LLRRUUDDFFBB
1 1 1
1 1 1
1 1 1
1 2 1
2 1 2
1 2 1