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>
const int MAX_N = 1000;
const int NODES = MAX_N * MAX_N + 4 * MAX_N;
int val[1 + NODES], right[1 + NODES], left[1 + NODES], up[1 + NODES],
    down[1 + NODES];
int line[MAX_N], column[MAX_N];
int id[MAX_N][MAX_N];
static inline void swap(int &a, int &b) {
  int aux = a;
  a = b;
  b = aux;
}
static inline int gotolc(int l, int c) {
  int curs;
  curs = line[l];
  while (c >= 0) {
    curs = right[curs];
    --c;
  }
  return curs;
}
int main() {
  int n, m, q, top = 0;
  int l1, c1, l2, c2, h, w;
  int curs1, curs2;
  scanf("%d%d%d", &n, &m, &q);
  for (int l = 0; l < n; ++l)
    for (int c = 0; c < m; ++c) {
      ++top;
      scanf("%d", &val[top]);
      id[l][c] = top;
    }
  for (int l = 0; l < n; ++l) {
    ++top;
    line[l] = top;
    right[top] = id[l][0];
    left[id[l][0]] = top;
    ++top;
    right[id[l][m - 1]] = top;
    left[top] = id[l][m - 1];
    if (l > 0) {
      up[id[l][0]] = id[l - 1][0];
      down[id[l - 1][0]] = id[l][0];
    }
  }
  for (int c = 0; c < m; ++c) {
    ++top;
    column[c] = top;
    down[top] = id[0][c];
    up[id[0][c]] = top;
    ++top;
    up[top] = id[n - 1][c];
    down[id[n - 1][c]] = top;
    if (c > 0) {
      left[id[0][c]] = id[0][c - 1];
      right[id[0][c - 1]] = id[0][c];
    }
  }
  for (int l = 1; l < n; ++l)
    for (int c = 1; c < m; ++c) {
      up[id[l][c]] = id[l - 1][c];
      down[id[l - 1][c]] = id[l][c];
      left[id[l][c]] = id[l][c - 1];
      right[id[l][c - 1]] = id[l][c];
    }
  for (int i = 0; i < q; ++i) {
    scanf("%d%d%d%d%d%d", &l1, &c1, &l2, &c2, &h, &w);
    --l1;
    --c1;
    --l2;
    --c2;
    curs1 = gotolc(l1, c1);
    curs2 = gotolc(l2, c2);
    for (int l = 0; l < h; ++l) {
      swap(right[left[curs1]], right[left[curs2]]);
      swap(left[curs1], left[curs2]);
      if (l < h - 1) {
        curs1 = down[curs1];
        curs2 = down[curs2];
      }
    }
    for (int c = 0; c < w; ++c) {
      swap(up[down[curs1]], up[down[curs2]]);
      swap(down[curs1], down[curs2]);
      if (c < w - 1) {
        curs1 = right[curs1];
        curs2 = right[curs2];
      }
    }
    for (int l = 0; l < h; ++l) {
      swap(left[right[curs1]], left[right[curs2]]);
      swap(right[curs1], right[curs2]);
      if (l < h - 1) {
        curs1 = up[curs1];
        curs2 = up[curs2];
      }
    }
    for (int c = 0; c < w; ++c) {
      swap(down[up[curs1]], down[up[curs2]]);
      swap(up[curs1], up[curs2]);
      curs1 = left[curs1];
      curs2 = left[curs2];
    }
  }
  for (int l = 0; l < n; ++l) {
    curs1 = line[l];
    for (int c = 0; c < m; ++c) {
      curs1 = right[curs1];
      printf("%d ", val[curs1]);
    }
    printf("\n");
  }
  return 0;
}