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;
int val[1005][1005];
struct Node {
  int val;
  Node *l, *r, *u, *d;
  Node() { l = r = u = d = 0; }
} * nodes[1005 * 1005];
int n, m;
inline int Cod(int x, int y) { return x * (m + 2) + (y + 1); }
inline bool Ok(int x, int y) {
  if (x < 0 || x > n + 1 || y < 0 || y > m + 1) return false;
  return true;
}
inline Node *Find(int x, int y) {
  Node *sol = nodes[Cod(x, 0)];
  for (int i = 1; i <= y; ++i) sol = sol->r;
  return sol;
}
inline void Show() {
  Node *nod = nodes[2], *nod1;
  int i, j;
  for (i = 1; i <= n; ++i) {
    nod = nod->d;
    for (nod1 = nod, j = 1; j <= m; ++j, nod1 = nod1->r)
      printf("%d ", nod1->val);
    printf("\n");
  }
}
int main() {
  int i, j, i1, j1, q;
  int x1, y1, x2, y2, L, C;
  scanf("%d%d%d", &n, &m, &q);
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j) scanf("%d", &val[i][j]);
  for (i = 0; i <= n + 1; ++i)
    for (j = 0; j <= m + 1; ++j) {
      int code = Cod(i, j);
      nodes[code] = new Node();
      nodes[code]->val = val[i][j];
    }
  for (i = 0; i <= n + 1; ++i)
    for (j = 0; j <= m + 1; ++j) {
      int code = Cod(i, j);
      if (Ok(i - 1, j)) nodes[code]->u = nodes[Cod(i - 1, j)];
      if (Ok(i, j + 1)) nodes[code]->r = nodes[Cod(i, j + 1)];
      if (Ok(i + 1, j)) nodes[code]->d = nodes[Cod(i + 1, j)];
      if (Ok(i, j - 1)) nodes[code]->l = nodes[Cod(i, j - 1)];
    }
  while (q--) {
    cin >> x1 >> y1 >> x2 >> y2 >> C >> L;
    Node *n1 = Find(x1, y1);
    Node *n2 = Find(x2, y2);
    for (i = 0; i < L; ++i) {
      Node *cn1u = n1->u;
      n1->u = n2->u;
      n2->u->d = n1;
      n2->u = cn1u;
      cn1u->d = n2;
      n1 = n1->r;
      n2 = n2->r;
    }
    n1 = n1->l;
    n2 = n2->l;
    for (i = 0; i < C; ++i) {
      Node *cn1r = n1->r;
      n1->r = n2->r;
      n2->r->l = n1;
      n2->r = cn1r;
      cn1r->l = n2;
      n1 = n1->d;
      n2 = n2->d;
    }
    n1 = n1->u;
    n2 = n2->u;
    for (i = 0; i < L; ++i) {
      Node *cn1d = n1->d;
      n1->d = n2->d;
      n2->d->u = n1;
      n2->d = cn1d;
      cn1d->u = n2;
      n1 = n1->l;
      n2 = n2->l;
    }
    n1 = n1->r;
    n2 = n2->r;
    for (i = 0; i < C; ++i) {
      Node *cn1l = n1->l;
      n1->l = n2->l;
      n2->l->r = n1;
      n2->l = cn1l;
      cn1l->r = n2;
      n1 = n1->u;
      n2 = n2->u;
    }
  }
  Show();
  return 0;
}