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 MAXN = 1000;
const int MAXM = 1000;
struct CrossList {
  struct Node {
    Node *left, *right, *up, *down;
    int val;
    Node(const int val)
        : left(NULL), right(NULL), up(NULL), down(NULL), val(val) {}
  } * origin;
  CrossList(const int n, const int m, int *a) {
    Node *lastRow = NULL, *lastRowFirst = NULL, *currRow = origin;
    for (int i = 0; i < n; i++) {
      currRow = new Node(*a++);
      if (i == 0) origin = currRow;
      linkUpDown(lastRowFirst, currRow);
      lastRow = lastRowFirst;
      lastRowFirst = currRow;
      for (int j = 1; j < m; j++) {
        if (lastRow) lastRow = lastRow->right;
        Node *newNode = new Node(*a++);
        linkLeftRight(currRow, newNode);
        linkUpDown(lastRow, newNode);
        currRow = newNode;
      }
    }
  }
  void linkLeftRight(Node *leftNode, Node *rightNode) {
    if (leftNode) leftNode->right = rightNode;
    if (rightNode) rightNode->left = leftNode;
  }
  void linkUpDown(Node *upNode, Node *downNode) {
    if (upNode) upNode->down = downNode;
    if (downNode) downNode->up = upNode;
  }
  void fetch(int *a) {
    for (Node *firstOfRow = origin; firstOfRow; firstOfRow = firstOfRow->down) {
      for (Node *v = firstOfRow; v; v = v->right) {
        *a++ = v->val;
      }
    }
  }
  void validate() {
    for (Node *firstOfRow = origin; firstOfRow; firstOfRow = firstOfRow->down) {
      for (Node *v = firstOfRow; v; v = v->right) {
        if (v->up) assert(v->up->down == v);
        if (v->down) assert(v->down->up == v);
        if (v->left) assert(v->left->right == v);
        if (v->right) assert(v->right->left == v);
      }
    }
  }
  Node *find(const int x, const int y) {
    Node *v = origin;
    for (int i = 0; i < x; i++) v = v->right;
    for (int i = 0; i < y; i++) v = v->down;
    return v;
  }
  void swap(const int x1, const int y1, const int x2, const int y2,
            const int width, const int height) {
    Node *a = find(x1, y1), *b = find(x2, y2), *currA, *currB;
    if (x1 == 0 && y1 == 0)
      origin = b;
    else if (x2 == 0 && y2 == 0)
      origin = a;
    currA = a, currB = b;
    for (int i = 0; i < width; i++) {
      Node *aUp = currA->up, *bUp = currB->up;
      linkUpDown(bUp, currA);
      linkUpDown(aUp, currB);
      if (i != width - 1) {
        currA = currA->right;
        currB = currB->right;
      }
    }
    for (int i = 0; i < height; i++) {
      Node *aRight = currA->right, *bRight = currB->right;
      linkLeftRight(currA, bRight);
      linkLeftRight(currB, aRight);
      currA = currA->down;
      currB = currB->down;
    }
    currA = a, currB = b;
    for (int i = 0; i < height; i++) {
      Node *aLeft = currA->left, *bLeft = currB->left;
      linkLeftRight(bLeft, currA);
      linkLeftRight(aLeft, currB);
      if (i != height - 1) {
        currA = currA->down;
        currB = currB->down;
      }
    }
    for (int i = 0; i < width; i++) {
      Node *aDown = currA->down, *bDown = currB->down;
      linkUpDown(currA, bDown);
      linkUpDown(currB, aDown);
      currA = currA->right;
      currB = currB->right;
    }
  }
};
int main() {
  int n, m, k;
  scanf("%d %d %d", &n, &m, &k);
  static int a[MAXN * MAXM];
  for (int i = 0, *p = a; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", p++);
  CrossList list(n, m, a);
  while (k--) {
    int x1, y1, x2, y2, width, height;
    scanf("%d %d %d %d %d %d", &y1, &x1, &y2, &x2, &height, &width), x1--, y1--,
        x2--, y2--;
    list.swap(x1, y1, x2, y2, width, height);
  }
  list.fetch(a);
  for (int i = 0, *p = a; i < n; i++)
    for (int j = 0; j < m; j++) printf("%d%c", *p++, j == m - 1 ? '\n' : ' ');
  fclose(stdin);
  fclose(stdout);
  return 0;
}