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:
//package e_contest_8;

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 Workingroutine {
	static class Node{
		Node down, right;
		int val;
		
		public Node(int val) {
			this.val = val;
		}
		
	}
public static void main(String[] args) throws IOException {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int m = sc.nextInt();
	mat =new Node[n+1][m+1];
	mat[0][0] =new Node(0);
	for (int i = 1;i <= n; i++) {
		mat[i-1][0].down = mat[i][0] = new Node(0);
	}
	for(int i = 1;i <= m; i++) {
		mat[0][i-1].right= mat[0][i] = new Node(0); 
	}
	int q = sc.nextInt();
	for (int i = 1; i < n+1; i++) {
		for (int j = 1; j < m+1; j++) {
			mat[i-1][j].down = mat[i][j-1].right = mat[i][j] = new Node(sc.nextInt());
		}
	}
	PrintWriter out =new PrintWriter(System.out);
//	for (int i = 1; i < mat.length; i++) {
//		for (int j = 1; j < mat[0].length; j++) {
//			out.print(mat[i][j].val+" ");
//		}
//		out.println();
//	}
	while(q-->0) {
		int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), d = sc.nextInt();
		int h = sc.nextInt(), w = sc.nextInt();
		Node [] x1 = getRow(a-1, b,w), xx1 = getRow(a+h-1,b,w);
		Node [] y1 = getCol(a, b-1, h), yy1 = getCol(a,b-1+w, h);
		Node [] x2 = getRow(c-1, d,w), xx2 = getRow(c+h-1,d,w);
		Node [] y2 = getCol(c, d-1, h), yy2 = getCol(c,d-1+w, h);
		switchRow(x1,x2);
		switchRow(xx1, xx2);
		switchCol(y1, y2);
		switchCol(yy1,yy2);
		
	}
	int [][] ans =new int[n][m];
	for (int i = 1; i < mat.length; i++) {
		Node top = mat[i][0].right;
		int count = 0;
		while(top!=null) {
			ans[i-1][count++] = top.val;
			top = top.right;
		}
	}
	for (int i = 0; i < ans.length; i++) {
		for (int j = 0; j < ans[i].length; j++) {
			out.print(ans[i][j]+" ");
		}
		out.println();
	}
	out.flush();
	out.close();
	
}
static void switchRow(Node[] one, Node [] two) {
	
	for (int i = 0; i < two.length; i++) {
		Node tmp = two[i].down;
//		System.out.println(/tmp.val);
		two[i].down = one[i].down;
		one[i].down = tmp;
//		System.out.println(tmp.val);
//		System.out.println();
	}
}
static void swapDown(Node[] x, Node[] y, int len)
{
	for(int i = 0; i < len; ++i)
	{
		Node d1 = x[i].down, d2 = y[i].down;
		x[i].down = d2;
		y[i].down = d1;
	}
}

static void swapRight(Node[] x, Node[] y, int len)
{
	for(int i = 0; i < len; ++i)
	{
		Node d1 = x[i].right, d2 = y[i].right;
		x[i].right = d2;
		y[i].right = d1;
	}
}

static void switchCol(Node[] one, Node [] two) {
	for (int i = 0; i < two.length; i++) {
		Node tmp = two[i].right;
		Node tmp2 = one[i].right;
		two[i].right = tmp2;
		one[i].right = tmp;
	}
}
static Node[][] mat;
static Node[] getRow(int a, int b,int w)
{
	Node[] ret = new Node[w];
	Node cur = mat[0][b];
	while(a-->0)
		cur = cur.down;
	for(int i = 0; i < w; ++i)
	{
		ret[i] = cur;
		cur = cur.right;
	}
	return ret;
}

static Node[] getCol(int a, int b,int h)
{
	Node[] ret = new Node[h];
	Node cur = mat[0][b];
	while(a-->0)
		cur = cur.down;
	for(int i = 0; i < h; ++i)
	{
		ret[i] = cur;
		cur = cur.down;
	}
	return ret;
}

static Node[] getRow2(int a, int b, int w) {
	System.out.println(a+" "+b+" "+w);
	Node cur = mat[0][b];//
	Node [] ret =new Node[w];
	while(a-->0)
		cur = cur.down;
	System.out.println(cur.val+ " current pointer");
//	ret[0] = cur;
	for(int i = 0;i<w;i++) {
		ret[i] = cur;
		System.out.print(ret[i].val+ " ");
		cur = cur.right;
	}
	System.out.println();
	return ret;
}
static Node[] getCol2(int a, int b,int h) {
	Node cur = mat[0][b];//
	Node [] ret =new Node[h];
	while(a-->0)
		cur = cur.down;
//	ret[0] = cur;
	for(int i = 0;i<h;i++) {
		ret[i] = cur;
		cur = cur.down;
	}
	return ret;
}
static class Scanner {
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream s) {
		br = new BufferedReader(new InputStreamReader(s));
	}//19 91 991 919 199

	public String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	public String nextLine() throws IOException {
		return br.readLine();
	}

	public double nextDouble() throws IOException {
		String x = next();
		StringBuilder sb = new StringBuilder("0");
		double res = 0, f = 1;
		boolean dec = false, neg = false;
		int start = 0;
		if (x.charAt(0) == '-') {
			neg = true;
			start++;
		}
		for (int i = start; i < x.length(); i++)
			if (x.charAt(i) == '.') {
				res = Long.parseLong(sb.toString());
				sb = new StringBuilder("0");
				dec = true;
			} else {
				sb.append(x.charAt(i));
				if (dec)
					f *= 10;
			}
		res += Long.parseLong(sb.toString()) / f;
		return res * (neg ? -1 : 1);
	}

	public boolean ready() throws IOException {
		return br.ready();
	}

}


}