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 long long N = 1e3 + 1;
const long long INF = 2e16 + 1;
const long long MOD = 1e9 + 7;
struct Cell {
  Cell *l, *d, *r, *u;
  int val;
  Cell() {}
  Cell(int val) : val(val), l(NULL), r(NULL), d(NULL), u(NULL) {}
  Cell(int val, Cell *l, Cell *d, Cell *r, Cell *u)
      : val(val), l(l), d(d), r(r), u(u) {}
};
Cell *cells[N][N];
int answer[N][N];
int main() {
  ios_base::sync_with_stdio(false);
  int n, m, q;
  cin >> n >> m >> q;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) {
      int x;
      cin >> x;
      cells[i][j] = new Cell(x);
    }
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) {
      if (j == 0)
        cells[i][j]->l = NULL;
      else
        cells[i][j]->l = cells[i][j - 1];
      if (i == n - 1)
        cells[i][j]->d = NULL;
      else
        cells[i][j]->d = cells[i + 1][j];
      if (j == m - 1)
        cells[i][j]->r = NULL;
      else
        cells[i][j]->r = cells[i][j + 1];
      if (i == 0)
        cells[i][j]->u = NULL;
      else
        cells[i][j]->u = cells[i - 1][j];
    }
  Cell *begcell = cells[0][0];
  for (long long i1 = 0; i1 < q; i1++) {
    int x1, y1, x2, y2, height, width;
    cin >> x1 >> y1 >> x2 >> y2 >> height >> width;
    Cell *cur1 = begcell;
    Cell *cur2 = begcell;
    if (x1 > x2 || x1 == x2 && y1 > y2) {
      swap(x1, x2);
      swap(y1, y2);
    }
    if (x1 == 1 && y1 == 1) {
      for (long long i = 0; i < x2 - 1; i++) begcell = begcell->d;
      for (long long i = 0; i < y2 - 1; i++) begcell = begcell->r;
    }
    for (long long i = 0; i < x1 - 1; i++) cur1 = cur1->d;
    for (long long i = 0; i < y1 - 1; i++) cur1 = cur1->r;
    for (long long i = 0; i < x2 - 1; i++) cur2 = cur2->d;
    for (long long i = 0; i < y2 - 1; i++) cur2 = cur2->r;
    for (long long i = 0; i < height; i++) {
      if (i) {
        cur1 = cur1->d;
        cur2 = cur2->d;
      }
      swap(cur1->l, cur2->l);
      if (cur1->l) cur1->l->r = cur1;
      if (cur2->l) cur2->l->r = cur2;
    }
    for (long long i = 0; i < width; i++) {
      if (i) {
        cur1 = cur1->r;
        cur2 = cur2->r;
      }
      swap(cur1->d, cur2->d);
      if (cur1->d) cur1->d->u = cur1;
      if (cur2->d) cur2->d->u = cur2;
    }
    for (long long i = 0; i < height; i++) {
      if (i) {
        cur1 = cur1->u;
        cur2 = cur2->u;
      }
      swap(cur1->r, cur2->r);
      if (cur1->r) cur1->r->l = cur1;
      if (cur2->r) cur2->r->l = cur2;
    }
    for (long long i = 0; i < width; i++) {
      if (i) {
        cur1 = cur1->l;
        cur2 = cur2->l;
      }
      swap(cur1->u, cur2->u);
      if (cur1->u) cur1->u->d = cur1;
      if (cur2->u) cur2->u->d = cur2;
    }
  }
  Cell *begcell1 = cells[0][0];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++)
      if (!cells[i][j]->l && !cells[i][j]->u) {
        begcell1 = cells[i][j];
      }
  for (long long i = 0; i < n; i++) {
    Cell *curcell = begcell1;
    assert(curcell->r);
    for (long long j = 0; j < m; j++) {
      answer[i][j] = curcell->val;
      if (j < m - 1) assert(curcell->r);
      curcell = curcell->r;
    }
    begcell1 = begcell1->d;
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) cout << answer[i][j] << " ";
    cout << endl;
  }
}