You are a student looking for a job. Today, you took an employment examination at an IT company. You were asked to write an efficient program to perform several operations on a square matrix.
Initially, you are given an N \times N matrix. Then you are given a series of operations. All operations except the last modify the matrix. After all operations, you must output a hash value computed from the resulting matrix as described below.
The available operations are:
WR r c v (Write): Write integer into cell , i.e. set A_{r, c}=v. (1 \le v \le 1,000,000)
CP r_1 c_1 r_2 c_2 (Copy): Copy the value in cell (r_1, c_1) to cell (r_2, c_2)
SR r_1 r_2 (Swap Rows): Swap rows r_1 and r_2
SC c_1 c_2 (Swap Columns): Swap columns c_1 and c_2
RL (Rotate Left): Rotate the entire matrix 90^\circ counterclockwise
RR (Rotate Right): Rotate the entire matrix 90^\circ clockwise
RH (Reflect Horizontal): Reverse the order of the rows
RV (Reflect Vertical): Reverse the order of the columns
The first line of each test case contains nine integers: , , , , , , , , .
1 \le N, Q \le 40\,000
1 \le A, B, C \le 1\,000\,000
1 \le r, c \le N
A_{r,c} = (r \times A + c \times B) \bmod C is the initial matrix value at position
1 \le D \le E \le N, 1 \le F \le G \le N, E-D \le 1\,000, G-F \le 1\,000
Next, lines follow, each describing an operation in the format above.
Output the integer hash value computed from the final matrix using the following algorithm:
h <- 314159265
for r = D...E
for c = F...G
h <- (31 * h + B_{r,c}) mod 100000007where <- indicates assignment, for i = S ... T means a loop for from to (inclusive), and mod is the remainder operation.
Example 1