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.util.*;
import java.io.*;

public class WorkingRoutine {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int Q = scanner.nextInt();
        Node[] rows = new Node[N];
        Node[] cols = new Node[M];
        int[][] mat = new int[N][M];
		Node[][] starters = new Node[N][M];
		for(int i = 0; i < N; i++) rows[i] = new Node(-1);
		for(int j = 0; j < M; j++) cols[j] = new Node(-1);
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < M; j++) {
                mat[i][j] = scanner.nextInt();
				Node cur = new Node(mat[i][j]);
				if (j == 0)  {
					rows[i].next = cur;
					cur.prev = rows[i];
				}
				else {
					starters[i][j-1].next = cur;
					cur.prev = starters[i][j-1];
				}
				if (j == M-1) {
					Node backSent = new Node(-1);
					cur.next = backSent;
					backSent.prev = cur;
				}
				if (i == 0) {
					cols[j].down = cur;
					cur.up = cols[j];
				}
				else {
					starters[i-1][j].down = cur;
					cur.up = starters[i-1][j];
				}
				if (i == N-1) {
					Node botSent = new Node(-1);
					cur.down = botSent;
					botSent.up = cur;
				}
				starters[i][j] = cur;
            }
        }
        while(Q-->0) {
			//for(int i = 0; i < N; i++) for(int j = 0; j < M; j++) {
				//System.out.println(starters[i][j].elt + " " + starters[i][j].up.elt + " " + starters[i][j].prev.elt);
			//}
            int a = scanner.nextInt()-1;
            int b = scanner.nextInt()-1;
            int c = scanner.nextInt()-1;
            int d = scanner.nextInt()-1;
            int h = scanner.nextInt();
            int w = scanner.nextInt();
            //interchange rows
            Node rowA = rows[a];
            Node rowC = rows[c];
            //walk each to c
            for(int j = 0; j <= b; j++) rowA = rowA.next;
            for(int j = 0; j <= d; j++) rowC = rowC.next;
			//walk across top
			Node prev, prev2 = null;
			for(int i = 0; i < w; i++) {
				prev = rowA.up;
				prev2 = rowC.up;
				rowA.up = prev2;
				prev2.down = rowA;
				rowC.up = prev;
				prev.down = rowC;
				if (i == w-1) break;
				rowA = rowA.next;
				rowC = rowC.next;
			}
			//now to right down portion
			for(int i = 0; i < h; i++) {
				prev = rowA.next;
				prev2 = rowC.next;
				rowA.next = prev2;
				prev2.prev = rowA;
				rowC.next = prev;
				prev.prev = rowC;
				if (i == h-1) break;
				rowA = rowA.down;
				rowC = rowC.down;
			}
			for(int i = 0; i < w; i++) {
				prev = rowA.down;
				prev2 = rowC.down;
				rowA.down = prev2;
				prev2.up = rowA;
				prev.up = rowC;
				rowC.down = prev;
				if(i==w-1)break;
				rowA = rowA.prev;
				rowC = rowC.prev;
			}
			for(int i =0; i < h; i++) {
				prev = rowA.prev;
				prev2 = rowC.prev;
				rowA.prev = prev2;
				prev2.next = rowA;
				prev.next = rowC;
				rowC.prev = prev;
				if(i==h-1)break;
				rowC = rowC.up;
				rowA = rowA.up;
			}
        }
        for(int i =0; i < N; i++) {
            Node curNode = rows[i].next;
            int cnt = 0;
            while(curNode.elt != -1) {
                if (cnt > 0) out.print(" ");
                cnt++;
                out.print(curNode.elt);
                curNode = curNode.next;
            }
            out.println();
        }
        out.flush();
    }
    
    static class Node {
        Node next = null, prev = null, up = null, down = null;
        int elt;
        public Node(int x) {elt = x;};
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        
        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
}