Description
Problem Description:
The astronauts lost their way in space, and now in his starting position, a virtual XYZ coordinate system, called an absolute coordinate system, in which the astronaut's frontal orientation is in the positive direction of the x-axis and the head is in the direction of the z-axis, the initial state of the astronaut is shown in the following illustration:
The six directions are respectively labeled, the x,y,z positive direction respectively is 0,1,2, the negative direction is 3,4,5 respectively, and they are called absolute directions. The astronaut walks in the universe only in the direction parallel to the XYZ axis of the absolute coordinate system, but he does not know his current absolute coordinates and the absolute direction he is facing.
Task Description:
Please determine the final absolute coordinates and orientation of the astronauts according to the astronauts ' description of their movements in the opposite direction. The description and significance of moving in a relative direction are as follows:
Forward x walk forward x m.
Back x turns first, then walks x meters.
Left X turns first and then x M.
Right x turns first and then x M.
Up X first face up, then walk x m.
Down X first face down, then walk x meters.
It looks up and down as shown in the following illustration:
Input
The first line is a positive integer m representing the number of groups to test the data. The first row of each set of test data is a positive integer n (1<=n<=10000) indicating the number of times astronauts walk, the following n rows per line Enter a relative walk, format as described above, where (1 <= x <= 10000 is a positive integer).
Output
For each set of input data output one row, x y z p, the middle is separated by a space, x y z is the absolute coordinates of the astronaut's position, p is the astronaut-oriented absolute direction number (0<=p <=5).
Sample Input
1 6 left Right one up
forward
15
Sample Output
23-10 12 3
Idea: Use a three-dimensional vector to record the direction of the human body--facing direction, the body vertical direction upward direction, the human left arm horizontally.
6 kinds of transformations are operations on this vector. (see Code for details)
Note: The title is the left-hand coordinate system