spoj#PPBRQ. Rotating Cube
Rotating Cube
Main Problem Source
The Farfaraway planet is an extraterrestrial one. Recent astronomers' researches show that this planet is cube-shaped, and a word is written on each side of the cube. Also this weird planet has 3 types of rotations around 3 axises. Those are:
Rotation of type X: Right and left sides remain still, and the cube turns upward.
Rotation of type Y: Front and rear sides remain still, and the cube turns toward right.
Rotation of type Z: Top and bottom sides remain still, and the cube turns toward right.
Given a cube with some words written on its each side and a sequence of rotations, you should determine the word on each cube side.
Input
First line of input contains an integer T, denoting number of testcases.
In each testcase First line contains six words (consisting of english letters, and not longer than 10 characters), which are the initial words on Front, Top, Bottom, Left, Right, and Rear side of the cube. Second line contains a number N, number of rotation sequences. Next N line contain a character X, Y or Z indicating type of the rotation, followed by m indicating that rotation was performed m times.
Here, 1<=T<=1000, 1<=N<=100000, 1<=m<=10^9.
Output
For each testcase, output the words on Front, Top, Bottom, Left, Right, and Rear side after applying those rotations.
Sample test(s)
input
2
Front Up Down Left Right Back
2
Z 4
X 4
Front Up Down Left Right Back
3
Z 1
X 1
Y 1
output
Front Up Down Left Right Back
Down Back Front Right Left Up
input
1
a b c d e f
3
X 5
Y 5
Z 5
output
f d e b c a