Problem description

Until now, we have only worked with one-dimensional arrays. We are now ready to explore two- dimensional arrays, called matrices (singular: matrix). A matrix represents a table with rows and columns.

In mathematics, a matrix is a rectangular array of numbers (or symbols or expressions), arranged in rows and columns. For example, the dimensions of the matrix below are 2 x 3, because there are two rows and three columns. The individual items in a matrix are called its elements.

1 9 13
20 5 6

For this assignment, you will implement a program that performs a variety of operations on a square matrix of size N x N, where each element is an integer in the interval 0...9. Your program will perform a set of operations on the matrix sequentially, then print the matrix. All operations affect the matrix in place.

There are five different known operations:

row a b - Row a is swapped with row b.

col a b - Column a is swapped with column b.

inc - Every element is incremented by 1 (modulo 10). (If after adding 1 an element becomes 10, we change it to 0.)

dec - Every element is decremented by 1 (modulo 10). (If after subtracting 1 an element becomes -1, we change it to 9.)

transpose - Transpose the matrix. Transposing a matrix means turning all the rows of the given matrix into columns and vice-versa. Example:

1 2 3
4 5 6
7 8 9

after transposing becomes

1 4 7
2 5 8
3 6 9

Input specification

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 interval 0...9. Next there is a line with an integer M (M < 50). Each of the next M lines contain one operation. If the command is row a b or col a b, then you can assume 1 <= a, b >= N and a ≠ b.

Output specification

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).

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

Use input redirection to read the input from a file, e.g. ./pa08b < input.txt

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.