시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 64 MB298827.586%

문제

Let us define a set of operations on a rectangular matrix of printable characters. 

A matrix $A$ with $m$ rows (1-st index) and $n$ columns (2-nd index) is given. The resulting matrix $B$ is defined as follows. 

  • Transposition by the main diagonal (operation identifier is '1'): $B_{j,i}=A_{i,j}$
  • Transposition by the second diagonal ('2'): $B_{n-j+1,m-i+1}=A_{i,j}$
  • Horizontal flip ('H'): $B_{m-i+1,j}=A_{i,j}$
  • Vertical flip ('V'): $B_{i,n-j+1}=A_{i,j}$
  • Rotation by 90 ('A'), 180 ('B'), or 270 ('C') degrees clockwise; 90 degrees case: $B_{j,m-i+1}=A_{i,j}$
  • Rotation by 90 ('X'), 180 ('Y'), or 270 ('Z') degrees counterclockwise; 90 degrees case: $B_{n-j+1,i}=A_{i,j}$

You are given a sequence of no more than $100\,000$ operations from the set. Apply the operations to the given matrix and output the resulting matrix.

입력

At the first line of the input file there are two integer numbers --- $m$ and $n$ ($0 < m,n \le 300$). Then there are $m$ lines with $n$ printable characters per line (we define a printable character as a symbol with ASCII code from 33 to 126 inclusive). There will be no additional symbols at these lines.

The next line contains the sequence operations to be performed, specified by their one-character identifiers. The operations should be performed from left to right.

출력

Two integer numbers, the number of rows and columns in the output matrix. Then the output matrix must follow, in the same format as the input one.

예제 입력 1

3 4
0000
a0b0
cdef
A1

예제 출력 1

3 4
cdef
a0b0
0000