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


public class E367 {
	public static void main(String[] args) {
		MyScanner scan = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		int R = scan.nextInt(), C = scan.nextInt(), Q = scan.nextInt();
		
		Cell[][] mat = new Cell[R+2][C+2];
		for(int i=0;i<=R+1;i++)
			for(int j=0;j<=C+1;j++){
				if(i==0||j==0||i==R+1||j==C+1)mat[i][j] = new Cell(0);
				else mat[i][j] = new Cell(scan.nextInt());
			}
		
		for(int i=0;i<=R+1;i++){
			for(int j=0;j<=C+1;j++){
				if(i!=0)mat[i][j].up = mat[i-1][j];
				if(j!=0)mat[i][j].left = mat[i][j-1];
				if(i!=R+1)mat[i][j].down = mat[i+1][j];
				if(j!=C+1)mat[i][j].right = mat[i][j+1];
			}
		}
		
		for(int i=0;i<Q;i++){
			int a = scan.nextInt(), b = scan.nextInt(), c = scan.nextInt(), d = scan.nextInt();
			int h = scan.nextInt(), w = scan.nextInt();
			
			Cell A = getCell(a,b, mat[0][0]), B = getCell(c,d,mat[0][0]);
			//top
			for(int j=0;j<w;j++){
				Cell tA = A.up, tB = B.up;
				A.up = tB; B.up=tA;tB.down = A;tA.down=B;
				if(j<w-1){A=A.right;B=B.right;}
			}
			//right
			for(int j=0;j<h;j++){
				Cell tA = A.right,tB = B.right;
				A.right = tB; B.right=tA;tB.left = A;tA.left=B;
				if(j<h-1){A=A.down;B=B.down;}
			}
			//bott
			for(int j=0;j<w;j++){
				Cell tA = A.down, tB = B.down;
				A.down = tB; B.down=tA;tB.up = A;tA.up=B;
				if(j<w-1){A=A.left;B=B.left;}
			}
			//left
			for(int j=0;j<h;j++){
				Cell tA = A.left,tB = B.left;
				A.left = tB; B.left=tA;tB.right = A;tA.right=B;
				if(j<h-1){A=A.up;B=B.up;}
			}
		}
		
		Cell temp = mat[0][0];
		for(int i=0;i<R;i++){
			temp = temp.down;
			Cell t = temp;
			for(int j=0;j<C;j++){
				t = t.right;
				out.print(t.val+" ");
			}out.println();
		}
		out.close();
	}
	
	private static Cell getCell(int a, int b, Cell x) {
		Cell temp = x;
		while(a>0){
			temp = temp.down;
			a--;
		}
		while(b>0){
			temp=temp.right;
			b--;
		}
		return temp;
	}

	private static class Cell {
		int val;
		Cell left, right, up, down;
		public Cell(int val){this.val=val;}
	}
	private static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {br = new BufferedReader(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());}
	}
}