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.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;


public class E {



	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt();
		int m = sc.nextInt();
		int q = sc.nextInt();

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

		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++)
				g[i][j] = sc.nextInt();

		Grid grid = new Grid(g);

		for (int i = 0; i < q; i++)  
			grid.swap(sc.nextInt() - 1, sc.nextInt() - 1, sc.nextInt() - 1, sc.nextInt() - 1, sc.nextInt(), sc.nextInt());

		for (Cell c : grid.rows) {
			for (int j = 0; j < m; j++) {
				out.print(c.v + " ");
				c = c.right;
			}
			out.println();
		}

		out.flush();
		out.close();
	}

	static class Grid {
		Cell[] rows;

		public Grid(int[][] g) {
			int n = g.length;
			int m = g[0].length;

			rows = new Cell[n];

			Cell up = null;
			for (int i = 0; i < n; i++) {
				rows[i] = new Cell(g[i][0], i);
				Cell before = rows[i];
				if(i > 0) {
					rows[i].up = rows[i - 1];
					rows[i - 1].down = rows[i];
				}
				for (int j = 1; j < m; j++) {
					Cell cur = new Cell(g[i][j], -1);
					cur.left = before;
					before.right = cur;
					before = cur;
					if(up != null) {
						up.down = cur;
						cur.up = up;
						up = up.right;
					}
				}

				up = rows[i].right;
			}
		}

		public void swap (int a, int b, int c, int d, int h, int w) {
			Cell c1 = rows[a];
			for (int i = 0; i < b; i++)
				c1 = c1.right;
			Cell c2 = rows[c];
			for (int i = 0; i < d; i++) 
				c2 = c2.right;



			for (int i = 0; i < w; i++) {
				Cell t = c1.up;
				c1.up = c2.up;
				c2.up = t;
				if(c1.up != null)
					c1.up.down = c1;
				if(c2.up != null)
					c2.up.down = c2;
				if(i < w - 1) {
					c1 = c1.right;
					c2 = c2.right;
				}
			}

			for (int i = 0; i < h; i++) {
				Cell t = c1.right;
				c1.right = c2.right;
				c2.right = t;
				if(c1.right != null)
					c1.right.left = c1;
				if(c2.right != null)
					c2.right.left = c2;
				if(i < h - 1) {
					c1 = c1.down;
					c2 = c2.down;
				}
			}

			for (int i = 0; i < w; i++) {
				Cell t = c1.down;
				c1.down = c2.down;
				c2.down = t;
				if(c1.down != null)
					c1.down.up = c1;
				if(c2.down != null)
					c2.down.up = c2;
				if(i < w - 1) {
					c1 = c1.left;
					c2 = c2.left;
				}
			}

			for (int i = 0; i < h; i++) {
				if(c1.start != -1)
					rows[c1.start] = c2;
				if(c2.start != -1)
					rows[c2.start] = c1;
				int tmp = c1.start;
				c1.start = c2.start;
				c2.start = tmp;

				Cell t = c1.left;
				c1.left = c2.left;
				c2.left = t;
				if(c1.left != null)
					c1.left.right = c1;
				if(c2.left != null)
					c2.left.right = c2;
				if(i < h - 1) {
					c1 = c1.up;
					c2 = c2.up;
				}
			}


		}
	}

	static class Cell {
		int v, start;
		Cell up, down, left, right;

		public Cell(int v, int s) {
			this.v = v; this.start = s;
		}
	}

	static class Scanner 
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream System){br = new BufferedReader(new InputStreamReader(System));}
		public String next() throws IOException 
		{
			while (st == null || !st.hasMoreTokens()) 
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public String nextLine()throws IOException{return br.readLine();}
		public int nextInt() throws IOException {return Integer.parseInt(next());}
		public double nextDouble() throws IOException {return Double.parseDouble(next());}
		public char nextChar()throws IOException{return next().charAt(0);}
		public Long nextLong()throws IOException{return Long.parseLong(next());}
		public boolean ready() throws IOException{return br.ready();}
		public void waitForInput(){for(long i = 0; i < 3e9; i++);}
	}


}