Magic Cube
시간 제한1초메모리 제한2048 MB
x, y, z축을 기준으로 일부 층을 누적해서 회전시키면서 n x n x n 큐브의 각 칸에 있는 번호를 관리하고, 질의한 위치의 번호를 출력한다.
문제
Imagine you are holding an cube, which is split up into smaller cubes labeled from 1 to . The orientation of the axes is left-to-right for the -axis, back-to-front for the -axis, and bottom-to-top for the -axis. For example, a cube is labeled as such:
Bottom layer ():
1 2
3 4
Top layer ():
5 6
7 8
In the context of a cube:
- Cube 1 is at (1, 1, 1).
- Cube 2 is at (2, 1, 1).
- Cube 3 is at (1, 2, 1).
- Cube 5 is at (1, 1, 2).
Each time you rotate the cube at slice along one of the -, -, and - axes, you are rotating the th layer along the corresponding axis, as well as all the layers after in the increasing direction of that axis.

입력
The first line contains two integers, () and (), the size of the cube and the number of operations.
Each of the next lines contains the information regarding an operation, and will be one of the following:
x, , : Rotate slices through slice by degrees counterclockwise around the -axis.y, , : Rotate slices through slice by degrees counterclockwise around the -axis.z, , : Rotate slices through slice by degrees counterclockwise around the -axis.q x y z: This is a query operation. Output which cube is at location .
For the first three operations, it is guaranteed that and . For queries, denotes the query location and . It is guaranteed there will be at least one query. The cube does not reset between operations. That is, rotations are cumulative.
출력
For each query operation, output which cube is at the given location.