#arc153b. [arc153_b]Grid Rotations

[arc153_b]Grid Rotations

Problem Statement

We have a grid with HH rows from top to bottom and WW columns from left and right. Initially, the square at the ii-th row from the top and jj-th column from the left has a lowercase English letter Ai,jA_{i,j}.

Let us perform QQ operations on this grid. In the ii-th operation, we are given integers aia_i and bib_i such that 1leqaileqH11\\leq a_i \\leq H-1 and 1leqbileqW11\\leq b_i\\leq W-1, and do the following.

  • Let R1R_1, R2R_2, R3R_3, and R4R_4 be rectangular regions within the grid defined as follows:
    • R1R_1 is the intersection of the top aia_i rows and leftmost bib_i columns;
    • R2R_2 is the intersection of the top aia_i rows and rightmost WbiW-b_i columns;
    • R3R_3 is the intersection of the bottom HaiH-a_i rows and leftmost bib_i columns;
    • R4R_4 is the intersection of the bottom HaiH-a_i rows and rightmost WbiW-b_i columns.
  • Rotate 180180 degrees each of R1R_1, R2R_2, R3R_3, and R4R_4.

Here, a 180180-degree rotation of a rectangular region RR within the grid moves the character on the square at the ii-th from the top and jj-th column from the left in RR to the square at the ii-th from the bottom and jj-th column from the right in RR. See also the figures for the samples.

Print the grid after all QQ operations.

Constraints

  • 2leqH,W2\\leq H, W, and HWleq5times105HW \\leq 5\\times 10^5.
  • Ai,jA_{i,j} is a lowercase English letter.
  • 1leqQleq2times1051\\leq Q\\leq 2\\times 10^5
  • 1leqaileqH11\\leq a_i\\leq H - 1
  • 1leqbileqW11\\leq b_i\\leq W - 1

Input

The input is given from Standard Input in the following format:

HH WW A1,1cdotsA1,WA_{1,1}\\cdots A_{1, W} vdots\\vdots AH,1cdotsAH,WA_{H,1}\\cdots A_{H, W} QQ a1a_1 b1b_1 vdots\\vdots aQa_Q bQb_Q

Output

Print the grid after the operations in the following format, where Bi,jB_{i,j} is the character on the square (i,j)(i,j) on the final grid.

B1,1cdotsB1,WB_{1,1}\\cdots B_{1, W} vdots\\vdots BH,1cdotsBH,WB_{H,1}\\cdots B_{H, W}


Sample Input 1

4 5
abcde
fghij
klmno
pqrst
1
3 3

Sample Output 1

mlkon
hgfji
cbaed
rqpts

The grid will change as follows.


Sample Input 2

3 7
atcoder
regular
contest
2
1 1
2 5

Sample Output 2

testcon
oderatc
ularreg

The grid will change as follows.


Sample Input 3

2 2
ac
wa
3
1 1
1 1
1 1

Sample Output 3

ac
wa

The grid will change as follows.