11187 - Matrix manipulation   

Description

Given an N*N matrix (where 1 <= N <= 10), your job is to swap two specific rows i and j (where 0 <= i,j < N), and then rotate up column k (where 0 <= k < N) for one time.

 

For example:

 

Consider the following matrix and a given operation (i,j,k)=(1,3,1).

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

 

After the swap between rows 1 and 3, the matrix will become

 

1

2

3

4

5

16

17

18

19

20

11

12

13

14

15

6

7

8

9

10

21

22

23

24

25

 

Then, after rotating column 1, the matrix will become

 

1

17

3

4

5

16

12

18

19

20

11

7

13

14

15

6

22

8

9

10

21

2

23

24

25

 

You will be asked to perform such operations several times.

Input

The first line has N (1<=N<=10), which means the size of the matrix. The total number of elements in the matrix is thus N x N.

 

For the next N lines, each contains N integers, specifying the elements of the matrix. All of the integers in the same line are separated by a space.

 

The next line contains another integer M ( 0 < M <= 5 ), indicating the number of operations.

 

Finally in the last M lines, each contains 3 integers i,j,k ( 0 <= i,j,k < N ).

Output

The final matrix.

 

Print the elements of the matrix using the format "%3d".

 

Each row is ended with a newline character ' \n'.

Sample Input  Download

Sample Output  Download

Tags




Discuss