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;
inline int read() {
  int x = 0, w = 0;
  char ch = getchar();
  while (!isdigit(ch)) w |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
  return w ? -x : x;
}
struct node {
  int l, r, up, down;
  int val;
} a[1005][1005];
int n, m, q, b[1005][1005], cnt;
inline int calc(int x, int y) { return x * (m + 3) + y; }
inline pair<int, int> re_calc(int p) {
  return make_pair(p / (m + 3), p % (m + 3));
}
inline pair<int, int> dfs(int x, int y, int xx, int yy) {
  if (xx) {
    pair<int, int> now = re_calc(a[x][y].down);
    return dfs(now.first, now.second, xx - 1, yy);
  }
  if (yy) {
    pair<int, int> now = re_calc(a[x][y].r);
    return dfs(now.first, now.second, xx, yy - 1);
  }
  return make_pair(x, y);
}
inline pair<int, int> dfs2(int x, int y, int xx, int yy) {
  if (yy) {
    pair<int, int> now = re_calc(a[x][y].r);
    return dfs2(now.first, now.second, xx, yy - 1);
  }
  if (xx) {
    pair<int, int> now = re_calc(a[x][y].down);
    return dfs2(now.first, now.second, xx - 1, yy);
  }
  return make_pair(x, y);
}
int main() {
  n = read();
  m = read();
  q = read();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      a[i][j].val = read();
    }
  }
  for (int i = 0; i <= n + 1; i++)
    a[i][0].r = calc(i, 1), a[i][n + 1].l = calc(i, n);
  for (int i = 0; i <= m + 1; i++)
    a[0][i].down = calc(1, i), a[n + 1][i].up = calc(n, i);
  for (int i = 0; i <= m; i++)
    a[0][i].r = calc(0, i + 1), a[n + 1][i].r = calc(n + 1, i + 1);
  for (int i = 1; i <= m + 1; i++)
    a[0][i].l = calc(0, i - 1), a[n + 1][i].l = calc(n + 1, i - 1);
  for (int i = 0; i <= n; i++)
    a[i][0].down = calc(i + 1, 0), a[i][n + 1].down = calc(i + 1, n + 1);
  for (int i = 1; i <= n + 1; i++)
    a[i][0].up = calc(i - 1, 0), a[i][n + 1].up = calc(i - 1, n + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      a[i][j].l = calc(i, j - 1);
      a[i][j].r = calc(i, j + 1);
      a[i][j].up = calc(i - 1, j);
      a[i][j].down = calc(i + 1, j);
    }
  }
  for (int i = 1; i <= q; i++) {
    int x1 = read(), y1 = read(), x2 = read(), y2 = read(), h = read(),
        w = read();
    pair<int, int> now1 = dfs(0, 0, x1 - 1, y1);
    pair<int, int> now2 = dfs(0, 0, x2 - 1, y2);
    pair<int, int> now3 = dfs(0, 0, x1 - 1, y1 + w - 1);
    pair<int, int> now4 = dfs(0, 0, x2 - 1, y2 + w - 1);
    for (int j = 0; j < h; j++) {
      now1 = dfs(now1.first, now1.second, 1, 0);
      now2 = dfs(now2.first, now2.second, 1, 0);
      now3 = dfs(now3.first, now3.second, 1, 0);
      now4 = dfs(now4.first, now4.second, 1, 0);
      pair<int, int> u = re_calc(a[now1.first][now1.second].l);
      pair<int, int> v = re_calc(a[now2.first][now2.second].l);
      a[u.first][u.second].r = calc(now2.first, now2.second);
      a[v.first][v.second].r = calc(now1.first, now1.second);
      a[now1.first][now1.second].l = calc(v.first, v.second);
      a[now2.first][now2.second].l = calc(u.first, u.second);
      u = re_calc(a[now3.first][now3.second].r);
      v = re_calc(a[now4.first][now4.second].r);
      a[u.first][u.second].l = calc(now4.first, now4.second);
      a[v.first][v.second].l = calc(now3.first, now3.second);
      a[now3.first][now3.second].r = calc(v.first, v.second);
      a[now4.first][now4.second].r = calc(u.first, u.second);
    }
    now1 = dfs2(0, 0, x1, y1 - 1);
    now2 = dfs2(0, 0, x2, y2 - 1);
    now3 = dfs2(0, 0, x1 + h - 1, y1 - 1);
    now4 = dfs2(0, 0, x2 + h - 1, y2 - 1);
    for (int j = 0; j < w; j++) {
      now1 = dfs(now1.first, now1.second, 0, 1);
      now2 = dfs(now2.first, now2.second, 0, 1);
      now3 = dfs(now3.first, now3.second, 0, 1);
      now4 = dfs(now4.first, now4.second, 0, 1);
      pair<int, int> u = re_calc(a[now1.first][now1.second].up);
      pair<int, int> v = re_calc(a[now2.first][now2.second].up);
      a[u.first][u.second].down = calc(now2.first, now2.second);
      a[v.first][v.second].down = calc(now1.first, now1.second);
      a[now1.first][now1.second].up = calc(v.first, v.second);
      a[now2.first][now2.second].up = calc(u.first, u.second);
      u = re_calc(a[now3.first][now3.second].down);
      v = re_calc(a[now4.first][now4.second].down);
      a[u.first][u.second].up = calc(now4.first, now4.second);
      a[v.first][v.second].up = calc(now3.first, now3.second);
      a[now3.first][now3.second].down = calc(v.first, v.second);
      a[now4.first][now4.second].down = calc(u.first, u.second);
    }
  }
  for (int i = 1; i <= n; i++) {
    pair<int, int> now = dfs(0, 0, i, 0);
    for (int j = 1; j <= m; j++) {
      now = dfs(now.first, now.second, 0, 1);
      printf("%d ", a[now.first][now.second].val);
    }
    printf("\n");
  }
  return 0;
}