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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
int a[MAXN][MAXN];
int n, m, i, j, k, x, y, xx, yy, nn, mm, q;
int nowx, nowy, nexx, nexy;
int r[MAXN][MAXN][2];
int d[MAXN][MAXN][2];
inline int get() {
  char c;
  while ((c = getchar()) < 48 || c > 57)
    ;
  int res = c - 48;
  while ((c = getchar()) >= 48 && c <= 57) res = res * 10 + c - 48;
  return res;
}
inline void getpoint(int a, int b, int &x, int &y) {
  x = 0;
  y = 0;
  for (int i = 1; i <= b; i++) {
    int xx = r[x][y][0], yy = r[x][y][1];
    x = xx;
    y = yy;
  }
  for (int i = 1; i <= a; i++) {
    int xx = d[x][y][0], yy = d[x][y][1];
    x = xx;
    y = yy;
  }
}
int main() {
  cin >> n >> m;
  cin >> q;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) a[i][j] = get();
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= m; j++) r[i][j][0] = i, r[i][j][1] = j + 1;
    for (j = 0; j <= m; j++) d[i][j][0] = i + 1, d[i][j][1] = j;
  }
  while (q--) {
    int f, g;
    x = get();
    y = get();
    xx = get();
    yy = get();
    nn = get();
    mm = get();
    int b[4][4];
    getpoint(x, y - 1, b[0][0], b[0][1]);
    getpoint(xx, yy - 1, b[0][2], b[0][3]);
    getpoint(x, y + mm - 1, b[1][0], b[1][1]);
    getpoint(xx, yy + mm - 1, b[1][2], b[1][3]);
    getpoint(x - 1, y, b[2][0], b[2][1]);
    getpoint(xx - 1, yy, b[2][2], b[2][3]);
    getpoint(x + nn - 1, y, b[3][0], b[3][1]);
    getpoint(xx + nn - 1, yy, b[3][2], b[3][3]);
    nowx = b[0][0];
    nowy = b[0][1];
    nexx = b[0][2];
    nexy = b[0][3];
    for (i = 1; i <= nn; i++) {
      swap(r[nowx][nowy][0], r[nexx][nexy][0]);
      swap(r[nowx][nowy][1], r[nexx][nexy][1]);
      f = d[nowx][nowy][0];
      g = d[nowx][nowy][1];
      nowx = f;
      nowy = g;
      f = d[nexx][nexy][0];
      g = d[nexx][nexy][1];
      nexx = f;
      nexy = g;
    }
    nowx = b[1][0];
    nowy = b[1][1];
    nexx = b[1][2];
    nexy = b[1][3];
    for (i = 1; i <= nn; i++) {
      swap(r[nowx][nowy][0], r[nexx][nexy][0]);
      swap(r[nowx][nowy][1], r[nexx][nexy][1]);
      f = d[nowx][nowy][0];
      g = d[nowx][nowy][1];
      nowx = f;
      nowy = g;
      f = d[nexx][nexy][0];
      g = d[nexx][nexy][1];
      nexx = f;
      nexy = g;
    }
    nowx = b[2][0];
    nowy = b[2][1];
    nexx = b[2][2];
    nexy = b[2][3];
    for (i = 1; i <= mm; i++) {
      swap(d[nowx][nowy][0], d[nexx][nexy][0]);
      swap(d[nowx][nowy][1], d[nexx][nexy][1]);
      f = r[nowx][nowy][0];
      g = r[nowx][nowy][1];
      nowx = f;
      nowy = g;
      f = r[nexx][nexy][0];
      g = r[nexx][nexy][1];
      nexx = f;
      nexy = g;
    }
    nowx = b[3][0];
    nowy = b[3][1];
    nexx = b[3][2];
    nexy = b[3][3];
    for (i = 1; i <= mm; i++) {
      swap(d[nowx][nowy][0], d[nexx][nexy][0]);
      swap(d[nowx][nowy][1], d[nexx][nexy][1]);
      f = r[nowx][nowy][0];
      g = r[nowx][nowy][1];
      nowx = f;
      nowy = g;
      f = r[nexx][nexy][0];
      g = r[nexx][nexy][1];
      nexx = f;
      nexy = g;
    }
  }
  for (i = 1; i <= n; i++) {
    x = i;
    y = 0;
    for (j = 1; j <= m; j++) {
      xx = r[x][y][0];
      yy = r[x][y][1];
      x = xx;
      y = yy;
      printf("%d ", a[x][y]);
    }
    puts("");
  }
}