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;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 1003;
const int xx[4] = {0, 1, 0, -1};
const int yy[4] = {1, 0, -1, 0};
int ka() {
  int x = 0;
  while (1) {
    char y = getchar();
    if ('0' <= y && y <= '9')
      x = (x * 10) + (y - '0');
    else
      return x;
  }
}
struct ban {
  short x, y;
  ban() {}
  ban(int x, int y) {
    this->x = x;
    this->y = y;
  }
};
int n, m;
int s[N][N];
ban u[N][N][4];
ban ans[N];
ban u1[N], u2[N], d1[N], d2[N], l1[N], l2[N], r1[N], r2[N];
void swpp(ban& t1, ban& t2) {
  t1.x ^= t2.x;
  t2.x ^= t1.x;
  t1.x ^= t2.x;
  t1.y ^= t2.y;
  t2.y ^= t1.y;
  t1.y ^= t2.y;
}
void swp(ban t1, ban t2, int z) {
  swpp(u[u[t1.x][t1.y][z].x][u[t1.x][t1.y][z].y][(z + 2) % 4],
       u[u[t2.x][t2.y][z].x][u[t2.x][t2.y][z].y][(z + 2) % 4]);
  swpp(u[t1.x][t1.y][z], u[t2.x][t2.y][z]);
}
void tp() {
  for (int i = 1; i <= n; ++i) {
    ban t = ban(i, 0);
    for (int j = 1; j <= m; ++j) {
      t = u[t.x][t.y][0];
      printf("%d ", s[t.x][t.y]);
    }
    printf("\n");
  }
}
void solv() {
  int qq;
  n = ka();
  m = ka();
  qq = ka();
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      s[i][j] = ka();
    }
  }
  for (int x = 0; x <= n + 1; ++x) {
    for (int y = 0; y <= m + 1; ++y) {
      for (int i = 0; i < 4; ++i) {
        u[x][y][i] = ban(x + xx[i], y + yy[i]);
      }
    }
  }
  while (qq--) {
    int x1 = ka(), y1_ = ka(), x2 = ka(), y2 = ka(), h = ka(), w = ka();
    u1[0] = ban(x1, 0);
    u2[0] = ban(x2, 0);
    for (int j = 1; j <= max(y1_, y2) + w - 1; ++j) {
      u1[j] = u[u1[j - 1].x][u1[j - 1].y][0];
      u2[j] = u[u2[j - 1].x][u2[j - 1].y][0];
    }
    d1[0] = ban(x1 + h - 1, 0);
    d2[0] = ban(x2 + h - 1, 0);
    for (int j = 1; j <= max(y1_, y2) + w - 1; ++j) {
      d1[j] = u[d1[j - 1].x][d1[j - 1].y][0];
      d2[j] = u[d2[j - 1].x][d2[j - 1].y][0];
    }
    l1[0] = ban(0, y1_);
    l2[0] = ban(0, y2);
    for (int i = 1; i <= max(x1, x2) + h - 1; ++i) {
      l1[i] = u[l1[i - 1].x][l1[i - 1].y][1];
      l2[i] = u[l2[i - 1].x][l2[i - 1].y][1];
    }
    r1[0] = ban(0, y1_ + w - 1);
    r2[0] = ban(0, y2 + w - 1);
    for (int i = 1; i <= max(x1, x2) + h - 1; ++i) {
      r1[i] = u[r1[i - 1].x][r1[i - 1].y][1];
      r2[i] = u[r2[i - 1].x][r2[i - 1].y][1];
    }
    for (int j1 = y1_, j2 = y2; j1 <= y1_ + w - 1; ++j1, ++j2) {
      swp(u1[j1], u2[j2], 3);
    }
    for (int j1 = y1_, j2 = y2; j1 <= y1_ + w - 1; ++j1, ++j2) {
      swp(d1[j1], d2[j2], 1);
    }
    for (int i1 = x1, i2 = x2; i1 <= x1 + h - 1; ++i1, ++i2) {
      swp(l1[i1], l2[i2], 2);
    }
    for (int i1 = x1, i2 = x2; i1 <= x1 + h - 1; ++i1, ++i2) {
      swp(r1[i1], r2[i2], 0);
    }
  }
  tp();
}
int main() {
  int tt;
  tt = 1;
  while (tt--) solv();
  return 0;
}