Having Fun with Matrices

We have a matrix of size N × N . Each value of the matrix occupies an integer from [0, 9]. A few operations are going to be performed on this matrix. We would like to know how the matrix looks like after these operations are performed sequentially. There could be five different types of operations. row a b In this operation, row a is interchanged with row b. col a b In this operation, column a is interchanged with column b. inc In this operation, every cell value is increased by 1 (modulo 10). That is, if after adding 1, a cell value becomes 10 we change it to 0. dec In this operation, every cell value is decreased by 1 (modulo 10). That is, if after subtracting 1, a cell value becomes -1 we change it to 9. transpose In this operation, we simply transpose the matrix. Transposing a matrix, denoted by AT , means turning all the rows of the given matrix into columns and vice-versa. Example: 123 147 4 5 6 after transposing 2 5 8 789 369 Input The input file starts with an integer T (T < 50) that indicates the number of test cases. Each case starts with a positive integer N (N < 10) that represents the size of the matrix. The next N lines contain N integers each. The value of each integer is in the range [0, 9]. Next there is a line with an integer M (M < 50). Each of the next M lines contain an operation each. If the command is ‘row a b’ or‘colab’,thenyoucanassume1≤a,b≤N anda̸=b. Output For each case, output the case number on the first line. Then on the next N lines output the content of the final matrix. Print a blank line after each case (even after the very last one).

2/2 Sample Input 2 4 1234 5678 1234 5678 1 transpose 3 000 111 000 2 row 1 2 inc Sample Output Case #1 1515 2626 3737 4848 Case #2 222 111 111