Problem: Vasiliy finally got to work, where there is a huge amount of tasks waiting for him. Vasiliy is given a matrix consisting of n rows and m columns and q tasks. Each task is to swap two submatrices of the given matrix.

For each task Vasiliy knows six integers ai, bi, ci, di, hi, wi, where ai is the index of the row where the top-left corner of the first rectangle is located, bi is the index of its column, ci is the index of the row of the top-left corner of the second rectangle, di is the index of its column, hi is the height of the rectangle and wi is its width.

It's guaranteed that two rectangles in one query do not overlap and do not touch, that is, no cell belongs to both rectangles, and no two cells belonging to different rectangles share a side. However, rectangles are allowed to share an angle.

Vasiliy wants to know how the matrix will look like after all tasks are performed.

Input

The first line of the input contains three integers n, m and q (2 ≤ n, m ≤ 1000, 1 ≤ q ≤ 10 000) — the number of rows and columns in matrix, and the number of tasks Vasiliy has to perform.

Then follow n lines containing m integers vi, j (1 ≤ vi, j ≤ 109) each — initial values of the cells of the matrix.

Each of the following q lines contains six integers ai, bi, ci, di, hi, wi (1 ≤ ai, ci, hi ≤ n, 1 ≤ bi, di, wi ≤ m).

Output

Print n lines containing m integers each — the resulting matrix.

Examples

Input

4 4 2
1 1 2 2
1 1 2 2
3 3 4 4
3 3 4 4
1 1 3 3 2 2
3 1 1 3 2 2


Output

4 4 3 3
4 4 3 3
2 2 1 1
2 2 1 1


Input

4 2 1
1 1
1 1
2 2
2 2
1 1 4 1 1 2


Output

2 2
1 1
2 2
1 1

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class CF706E {

    static class Node {
        int val;
        Node down;
        Node right;

        public Node(int val) {
            this.val = val;
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);

        String[] line = br.readLine().split(" ");
        int n = toInt(line[0]);
        int m = toInt(line[1]);
        int q = toInt(line[2]);

        int[][] matrix = new int[n][m];

        for (int i = 0; i < n; i++) {
            line = br.readLine().split(" ");
            for (int j = 0; j < m; j++) {
                matrix[i][j] = toInt(line[j]);
            }
        }

        Node root = buildNodes(matrix);

        for (int i = 0; i < q; i++) {
            line = br.readLine().split(" ");
            int a = toInt(line[0]);
            int b = toInt(line[1]);
            int c = toInt(line[2]);
            int d = toInt(line[3]);
            int h = toInt(line[4]);
            int w = toInt(line[5]);
            root = switchSubMatrices(root, a - 1, b - 1, c - 1, d - 1, h, w, n, m);
        }
        printNodes(pw, root, n, m);
        pw.close();
        br.close();
    }

    public static void printNodes(PrintWriter pw, Node root, int n, int m) {
        Node rowHead = root;
        for (int i = 0; i < n; i++) {
            Node curr = rowHead;
            for (int j = 0; j < m; j++) {
                pw.print(curr.val + " ");
                curr = curr.right;
            }
            pw.println();
            rowHead = rowHead.down;
        }
    }

    public static Node buildNodes(int[][] mat) {
        int n = mat.length;
        int m = mat[0].length;
        Node[][] nodeMat = new Node[n][m];

        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                nodeMat[i][j] = new Node(mat[i][j]);

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                nodeMat[i][j].right = j < m - 1 ? nodeMat[i][j + 1] : null;
                nodeMat[i][j].down = i < n - 1 ? nodeMat[i + 1][j] : null;
            }
        }
        return nodeMat[0][0];
    }

    public static Node switchSubMatrices(Node root, int a, int b, int c, int d, int h, int w, int n, int m) {
        Node rect1 = findNode(root, a, b);
        Node rect2 = findNode(root, c, d);

        Node upperRow1 = findNode(root, a - 1, b);
        Node upperRow2 = findNode(root, c - 1, d);
        Node leftCol1 = findNode(root, a, b - 1);
        Node leftCol2 = findNode(root, c, d - 1);
        Node rightCol1 = findNode(root, a, b + w);
        Node rightCol2 = findNode(root, c, d + w);
        Node downRow1 = findNode(root, a + h, b);
        Node downRow2 = findNode(root, c + h, d);

        // Upper frame
        Node curr1 = rect1;
        Node curr2 = rect2;
        for (int i = 0; i < w; i++) {
            if (upperRow1 != null) {
                upperRow1.down = curr2;
                upperRow1 = upperRow1.right;
            }

            if (upperRow2 != null) {
                upperRow2.down = curr1;
                upperRow2 = upperRow2.right;
            }

            curr1 = curr1.right;
            curr2 = curr2.right;
        }

        // Left frame
        curr1 = rect1;
        curr2 = rect2;

        for (int i = 0; i < h; i++) {
            if (leftCol1 != null) {
                leftCol1.right = curr2;
                leftCol1 = leftCol1.down;
            }

            if (leftCol2 != null) {
                leftCol2.right = curr1;
                leftCol2 = leftCol2.down;
            }

            curr1 = curr1.down;
            curr2 = curr2.down;
        }

        // Right frame
        curr1 = findNode(rect1, 0, w - 1);
        curr2 = findNode(rect2, 0, w - 1);

        for (int i = 0; i < h; i++) {
            curr1.right = rightCol2;
            curr2.right = rightCol1;

            if (rightCol1 != null)
                rightCol1 = rightCol1.down;

            if (rightCol2 != null)
                rightCol2 = rightCol2.down;

            curr1 = curr1.down;
            curr2 = curr2.down;
        }

        // Bottom frame
        curr1 = findNode(rect1, h - 1, 0);
        curr2 = findNode(rect2, h - 1, 0);

        for (int i = 0; i < w; i++) {
            curr1.down = downRow2;
            curr2.down = downRow1;

            if (downRow1 != null)
                downRow1 = downRow1.right;

            if (downRow2 != null)
                downRow2 = downRow2.right;

            curr1 = curr1.right;
            curr2 = curr2.right;
        }
        return rect1 == root ? rect2 : rect2 == root ? rect1 : root; // Handle possible change of root
    }

    public static Node findNode(Node root, int r, int c) {
        if (r < 0 || c < 0)
            return null;

        Node node = root;
        for (int i = 0; i < r && node != null; i++)
            node = node.down;
        for (int i = 0; i < c && node != null; i++)
            node = node.right;
        return node;
    }

    public static int toInt(String s) {
        return Integer.parseInt(s);
    }
}