#B3991. Matrix Swap and Query Operations

    ID: 11648 Type: Default 1000ms 256MiB

Matrix Swap and Query Operations

Matrix Swap and Query Operations

Little B has a matrix \(a\) with \(n\) rows and \(m\) columns. He needs to perform \(q\) operations on the matrix. Each operation is one of the following three types:

  • \(1\ x\ y\): Swap the \(x\)-th row with the \(y\)-th row. (If \(x = y\), nothing happens.)
  • \(2\ x\ y\): Swap the \(x\)-th column with the \(y\)-th column. (If \(x = y\), nothing happens.)
  • \(3\ x\ y\): Query and output the current value of \(a_{x,y}\).

After executing all \(q\) operations, output the final state of the matrix \(a\). For each query operation (type 3), output the answer immediately in the order the queries appear, and then output the final matrix.

inputFormat

The input begins with a line containing three integers \(n\), \(m\), and \(q\) (the number of rows, columns, and operations, respectively).

The next \(n\) lines each contain \(m\) integers, representing the initial matrix \(a\). The \(i\)-th line corresponds to the \(i\)-th row of the matrix.

Then \(q\) lines follow, each describing an operation in one of the three formats specified above.

outputFormat

For every operation of type 3, output the queried value on its own line in the order they appear.

After processing all operations, output the final matrix \(a\) where each row is printed on a new line with elements separated by a single space.

sample

3 3 4
1 2 3
4 5 6
7 8 9
3 1 1
1 1 3
3 1 1
2 2 3
1

7 7 9 8 4 6 5 1 3 2

</p>