Memory limit: 256 MiB Time limit: 1000 ms Input file: stdin Output file: stdout
Problem type: traditional Judging mode: text compare

Description

Alice has a pixel stamper of $N$ x $N$ pixels, and she has a $N$ x $N$ pixel grid. A pixel on the stamper is described with a value $A$$i,j$.
A pixel on the pixel grid is described with value $B$$i,j$, which is initially $0$.

There are a total of $Q$ events, happening in chronological order:
    1. L-rotate: Alice left rotates her stamper (i.e. pixel $A$$i,j$ is now pixel $A$$N+1-j,i$, for all $1 \le i,j \le N$)
    2. R-rotate: Alice right rotates her stamper (i.e. pixel $A$$i,j$ is now pixel $A$$j,N+1-i$, for all $1 \le i,j \le N$)
    3. Stamp: Stamp the pixel stamper on the grid (i.e. add $A$$i,j$ to $B$$i,j$, for all $1 \le i,j \le N$)
    4. Query x y: Find the value of $B$$x,y$ ($1 \le x, y \le N$)

Help Alice to perform the operations!

Input

The first line contain two integers $N$ and $Q$.

The following $N$ lines each contains $N$ integers, representing the values in the pixel stamper. For line $i+1$, the $N$ integers represent $A$$i,1$ to $A$$i,N$ respectively.

The following Q lines contains an operation, either L-rotate, R-rotate, Stamp or Query x y.

Output

For each Query x y operation, output the value of $B$$x,y$ in a single line.

Sample

Sample input

3 7
1 2 3
4 5 6
7 8 9
Stamp
Stamp
Query 1 3
L-rotate
L-rotate
Stamp
Query 2 2

Sample output

6
15

Sample explaination

Values of B after 1st Stamp: 
0+1 0+2 0+3
0+4 0+5 0+6
0+7 0+8 0+9

Values of B after 2nd Stamp:
1+1 2+2 3+3
4+4 5+5 6+6
7+7 8+8 9+9

Values of B after 3rd Stamp: 
2+9 4+8 6+7
8+6 10+5 12+4
14+3 16+2 18+1

Constraint and hint

For all test data,
$1 \le N \le 1000$
$1 \le Q \le 10^5$
$1 \le A$$i,j$ $\le 10^6$

Subtask Score Additional Constraints
$1$ $11$ There are Stamp and Query operations only
$2$ $17$ $1 \le N,Q \le 300$
$3$ $23$ Stamp operation happens once and only once
$4$ $24$ All Query operations happens after Stamp operations
$5$ $25$ No additional Constraints

Scoring: Per Subtask
Authored by wy24215
Appeared in WYHK 2025 Mini Contest 4 [Pre-HKSC Heat]