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.InputStreamReader;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        ConsoleIO io = new ConsoleIO();
        new Main(io).solve();
        io.close();
    }

    ConsoleIO io;

    Main(ConsoleIO io) {
        this.io = io;
    }

    ArrayList<ArrayList<Edge>> gr;

    class Edge {
        public Edge(int uu, int vv, int ii) {
            u = uu;
            v = vv;
            i = ii;
        }

        public int u;
        public int v;
        public int i;
    }

    long MOD = 1_000_000_007;
    int N, M, Q;

    class Node{
        public int v;
        public Node right;
        public Node bottom;
    }

    public void solve() {
        N = io.ri();
        M = io.ri();
        Q = io.ri();

        Node[][] all = new Node[N + 1][M + 1];

        for (int i = 0; i <= N; i++)
            for (int j = 0; j <= M; j++) {
                Node a = new Node();
                if (i > 0 && j > 0)
                    a.v = io.ri();
                all[i][j] = a;
                if (i > 0) all[i - 1][j].bottom = a;
                if (j > 0) all[i][j - 1].right = a;
            }

        for (int q = 0; q < Q; q++) {
            int a = io.ri()-1, b = io.ri()-1, c = io.ri()-1, d = io.ri()-1, h = io.ri(), w = io.ri();
            Node n1 = all[0][0];
            while (a-- > 0) n1 = n1.bottom;
            while (b-- > 0) n1 = n1.right;
            Node n2 = all[0][0];
            while (c-- > 0) n2 = n2.bottom;
            while (d-- > 0) n2 = n2.right;

            ver(h, n1.bottom, n2.bottom);
            hor(w, n1.right,n2.right);

            Node t1 = n1, t2 = n2;
            int tw = w;
            while(w-->0){
                n1 = n1.right;
                n2 = n2.right;
            }
            ver(h,n1.bottom, n2.bottom);
            while(h-->0){
                t1 = t1.bottom;
                t2 = t2.bottom;
            }
            hor(tw, t1.right, t2.right);
        }

        StringBuilder sb = new StringBuilder();
        Node cur = all[0][0].bottom.right;
        for(int i = 0;i<N;i++) {
            if (i > 0) sb.append(System.lineSeparator());
            Node t = cur;
            for (int j = 0; j < M; j++) {
                sb.append(cur.v);
                sb.append(' ');
                cur = cur.right;
            }
            cur = t.bottom;
        }

        io.writeLine(sb.toString());
    }

    void ver(int h, Node f1, Node f2){
        while (h-- > 0) {
            Node t = f1.right;
            f1.right = f2.right;
            f2.right = t;
            f1 = f1.bottom;
            f2 = f2.bottom;
        }
    }

    void hor(int w, Node f1, Node f2){
        while (w-- > 0) {
            Node t = f1.bottom;
            f1.bottom = f2.bottom;
            f2.bottom = t;
            f1 = f1.right;
            f2 = f2.right;
        }
    }

}

class ConsoleIO {
    BufferedReader br;
    PrintWriter out;
    public ConsoleIO(){br = new BufferedReader(new InputStreamReader(System.in));out = new PrintWriter(System.out);}
    public void flush(){this.out.flush();}
    public void close(){this.out.close();}
    public void writeLine(String s) {this.out.println(s);}
    public void writeInt(int a) {this.out.print(a);this.out.print(' ');}
    public void writeWord(String s){
        this.out.print(s);
    }
    public void writeIntArray(int[] a, int k, String separator) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < k; i++) {
            if (i > 0) sb.append(separator);
            sb.append(a[i]);
        }
        this.writeLine(sb.toString());
    }
    public int read(char[] buf, int len){try {return br.read(buf,0,len);}catch (Exception ex){ return -1; }}
    public String readLine() {try {return br.readLine();}catch (Exception ex){ return "";}}
    public long[] readLongArray() {
        String[]n=this.readLine().trim().split("\\s+");long[]r=new long[n.length];
        for(int i=0;i<n.length;i++)r[i]=Long.parseLong(n[i]);
        return r;
    }
    public int[] readIntArray() {
        String[]n=this.readLine().trim().split("\\s+");int[]r=new int[n.length];
        for(int i=0;i<n.length;i++)r[i]=Integer.parseInt(n[i]);
        return r;
    }
    public int[] readIntArray(int n) {
        int[] res = new int[n];
        char[] all = this.readLine().toCharArray();
        int cur = 0;boolean have = false;
        int k = 0;
        boolean neg = false;
        for(int i = 0;i<all.length;i++){
            if(all[i]>='0' && all[i]<='9'){
                cur = cur*10+all[i]-'0';
                have = true;
            }else if(all[i]=='-') {
                neg = true;
            }
            else if(have){
                res[k++] = neg?-cur:cur;
                cur = 0;
                have = false;
                neg = false;
            }
        }
        if(have)res[k++] = neg?-cur:cur;
        return res;
    }
    public int ri() {
        try {
            int r = 0;
            boolean start = false;
            boolean neg = false;
            while (true) {
                int c = br.read();
                if (c >= '0' && c <= '9') {
                    r = r * 10 + c - '0';
                    start = true;
                } else if (!start && c == '-') {
                    start = true;
                    neg = true;
                } else if (start || c == -1) return neg ? -r : r;
            }
        } catch (Exception ex) {
            return -1;
        }
    }
    public long readLong() {
        try {
            long r = 0;
            boolean start = false;
            boolean neg = false;
            while (true) {
                int c = br.read();
                if (c >= '0' && c <= '9') {
                    r = r * 10 + c - '0';
                    start = true;
                } else if (!start && c == '-') {
                    start = true;
                    neg = true;
                } else if (start || c == -1) return neg ? -r : r;
            }
        } catch (Exception ex) {
            return -1;
        }
    }
    public String readWord() {
        try {
            boolean start = false;
            StringBuilder sb = new StringBuilder();
            while (true) {
                int c = br.read();
                if (c!= ' ' && c!= '\r' && c!='\n' && c!='\t') {
                    sb.append((char)c);
                    start = true;
                } else if (start || c == -1) return sb.toString();
            }
        } catch (Exception ex) {
            return "";
        }
    }
}
class Pair {
    public Pair(int a, int b) {this.a = a;this.b = b;}
    public int a;
    public int b;
}
class Tri {
    public Tri(int a, int b, int c) {this.a = a;this.b = b;this.c = c;}
    public int a;
    public int b;
    public int c;
}
class PairLL {
    public PairLL(long a, long b) {this.a = a;this.b = b;}
    public long a;
    public long b;
}