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;
struct Node {
  int val;
  Node *pt[4];
};
Node *At(Node *pretop, int r, int c) {
  c--;
  for (int a = 0; a < r; a++) pretop = pretop->pt[2];
  for (int b = 0; b < c; b++) pretop = pretop->pt[1];
  return pretop;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m, q;
  cin >> n >> m >> q;
  vector<vector<Node> > grid(n + 2, vector<Node>(m + 2));
  for (int a = 0; a < n + 2; a++)
    for (int b = 0; b < m + 2; b++) grid[a][b].val = 0;
  for (int a = 1; a <= n; a++)
    for (int b = 1; b <= m; b++) cin >> grid[a][b].val;
  for (int a = 1; a <= n; a++)
    for (int b = 1; b <= m; b++) {
      grid[a][b].pt[0] = &grid[a - 1][b];
      grid[a][b].pt[1] = &grid[a][b + 1];
      grid[a][b].pt[2] = &grid[a + 1][b];
      grid[a][b].pt[3] = &grid[a][b - 1];
      grid[a - 1][b].pt[2] = &grid[a][b];
      grid[a][b + 1].pt[3] = &grid[a][b];
      grid[a + 1][b].pt[0] = &grid[a][b];
      grid[a][b - 1].pt[1] = &grid[a][b];
    }
  for (int a = 0; a < q; a++) {
    int x[6];
    for (int b = 0; b < 6; b++) cin >> x[b];
    Node *adv[2];
    adv[0] = At(&grid[0][1], x[0], x[1]);
    adv[1] = At(&grid[0][1], x[2], x[3]);
    for (int b = 0; b < x[5]; b++) {
      swap(adv[0]->pt[0], adv[1]->pt[0]);
      swap(adv[0]->pt[0]->pt[2], adv[1]->pt[0]->pt[2]);
      adv[0] = adv[0]->pt[1];
      adv[1] = adv[1]->pt[1];
    }
    adv[0] = adv[0]->pt[3];
    adv[1] = adv[1]->pt[3];
    for (int b = 0; b < x[4]; b++) {
      swap(adv[0]->pt[1], adv[1]->pt[1]);
      swap(adv[0]->pt[1]->pt[3], adv[1]->pt[1]->pt[3]);
      adv[0] = adv[0]->pt[2];
      adv[1] = adv[1]->pt[2];
    }
    adv[0] = adv[0]->pt[0];
    adv[1] = adv[1]->pt[0];
    for (int b = 0; b < x[5]; b++) {
      swap(adv[0]->pt[2], adv[1]->pt[2]);
      swap(adv[0]->pt[2]->pt[0], adv[1]->pt[2]->pt[0]);
      adv[0] = adv[0]->pt[3];
      adv[1] = adv[1]->pt[3];
    }
    adv[0] = adv[0]->pt[1];
    adv[1] = adv[1]->pt[1];
    for (int b = 0; b < x[4]; b++) {
      swap(adv[0]->pt[3], adv[1]->pt[3]);
      swap(adv[0]->pt[3]->pt[1], adv[1]->pt[3]->pt[1]);
      adv[0] = adv[0]->pt[0];
      adv[1] = adv[1]->pt[0];
    }
  }
  vector<Node *> rbeg(n + 1);
  rbeg[0] = &grid[0][1];
  for (int a = 1; a <= n; a++) rbeg[a] = rbeg[a - 1]->pt[2];
  for (int a = 1; a <= n; a++) {
    Node *cur = rbeg[a];
    for (int b = 0; b < m; b++) {
      cout << cur->val << " ";
      cur = cur->pt[1];
    }
    cout << "\n";
  }
  cout << "\n";
  return 0;
}