PPBRQ - Rotating Cube

no tags 

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<=10001<=N<=1000001<=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

 


hide comments
Dune: 2020-01-11 03:58:03

Very nice problem. Just fun.

sonuverma: 2018-04-01 09:07:45

Very nice problem :-)

Thotsaphon Thanatipanonda: 2015-11-05 00:33:13

For completed description goto http://contest.bayan.ir/en/contest/qualification_2014/problem/C/

Input

First line of input contains an integer tt, denoting number of testcases.

In each testcase: First line contains six words (consisting of english letters, and not longer than 10 characters), which are thr initial words on Front, Top, Bottom, Left, Right, and Rear side of the cube. Second line contains a number nn, number of rotation sequences. Next nn line contain a character X, Y, or Z, indicating type of the rotation, followed by mm, indicating that rotation was performed mm times.

1 \le t \le 1001≤t≤100
1 \le n \le 100001≤n≤10000
1 \le m \le 10^91≤m≤10
​9
​​
Output

For each testcase, output the words on Front, Top, Bottom, Left, Right, and Rear side after applying those rotations.

Sample 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
Sample Output

Front Up Down Left Right Back
Down Back Front Right Left Up

sobriquet: 2015-01-23 13:15:52

No special test cases. Just double check your implementation.

wisfaq: 2014-10-31 13:32:07

I think the time limit is too strict for many languages. Some languages have a start up time of about 0.5 sec.
Moreover the input is rather huge.
If you want to keep it at 0.2 sec, please make a tutorial version with a less strict time limit.
Please inspect my most recent Pypy prog if I missed something important.

Last edit: 2014-10-31 13:49:53
Archangel: 2014-10-27 14:43:37

@Md. Najmuzzaman
very nice problem :)


Added by:Najmuzzaman
Date:2014-10-23
Time limit:0.200s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 GOSU
Resource:contest.bayan.ir/en/contest/qualification_2014