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 int INVALID = -1;
int n, m;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int LEFT = 1;
const int RIGHT = 0;
const int UP = 3;
const int DOWN = 2;
struct node {
  int value;
  struct node *ptr[4];
};
node matrix[1002][1002];
bool valid(int i, int j) {
  if (i < 0 || i > 1 + n || j < 0 || j > 1 + m) return 0;
  return 1;
}
void modify(int a, int b, int c, int d, int h, int w) {
  node *it1 = &matrix[a][0];
  node *it2 = &matrix[c][0];
  for (int i = 0; i < b; i++) it1 = it1->ptr[RIGHT];
  for (int i = 0; i < d; i++) it2 = it2->ptr[RIGHT];
  node *itr1 = it1;
  node *itr2 = it2;
  for (int i = 0; i < w - 1; i++) {
    swap(itr1->ptr[UP]->ptr[DOWN], itr2->ptr[UP]->ptr[DOWN]);
    swap(itr1->ptr[UP], itr2->ptr[UP]);
    itr1 = itr1->ptr[RIGHT];
    itr2 = itr2->ptr[RIGHT];
  }
  swap(itr1->ptr[UP]->ptr[DOWN], itr2->ptr[UP]->ptr[DOWN]);
  swap(itr1->ptr[UP], itr2->ptr[UP]);
  for (int i = 0; i < h - 1; i++) {
    swap(itr1->ptr[RIGHT]->ptr[LEFT], itr2->ptr[RIGHT]->ptr[LEFT]);
    swap(itr1->ptr[RIGHT], itr2->ptr[RIGHT]);
    itr1 = itr1->ptr[DOWN];
    itr2 = itr2->ptr[DOWN];
  }
  swap(itr1->ptr[RIGHT]->ptr[LEFT], itr2->ptr[RIGHT]->ptr[LEFT]);
  swap(itr1->ptr[RIGHT], itr2->ptr[RIGHT]);
  itr1 = it1;
  itr2 = it2;
  for (int i = 0; i < h - 1; i++) {
    swap(itr1->ptr[LEFT]->ptr[RIGHT], itr2->ptr[LEFT]->ptr[RIGHT]);
    swap(itr1->ptr[LEFT], itr2->ptr[LEFT]);
    itr1 = itr1->ptr[DOWN];
    itr2 = itr2->ptr[DOWN];
  }
  swap(itr1->ptr[LEFT]->ptr[RIGHT], itr2->ptr[LEFT]->ptr[RIGHT]);
  swap(itr1->ptr[LEFT], itr2->ptr[LEFT]);
  for (int i = 0; i < w - 1; i++) {
    swap(itr1->ptr[DOWN]->ptr[UP], itr2->ptr[DOWN]->ptr[UP]);
    swap(itr1->ptr[DOWN], itr2->ptr[DOWN]);
    itr1 = itr1->ptr[RIGHT];
    itr2 = itr2->ptr[RIGHT];
  }
  swap(itr1->ptr[DOWN]->ptr[UP], itr2->ptr[DOWN]->ptr[UP]);
  swap(itr1->ptr[DOWN], itr2->ptr[DOWN]);
}
void generateConnections() {
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= m + 1; j++) {
      for (int k = 0; k < 4; k++) {
        matrix[i][j].value = INVALID;
        if (valid(i + dx[k], j + dy[k]))
          matrix[i][j].ptr[k] = &matrix[i + dx[k]][j + dy[k]];
        else
          matrix[i][j].ptr[k] = nullptr;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q;
  cin >> n >> m >> q;
  generateConnections();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> matrix[i][j].value;
    }
  }
  while (q--) {
    int a, b, c, d, h, w;
    cin >> a >> b >> c >> d >> h >> w;
    modify(a, b, c, d, h, w);
  }
  for (int i = 1; i <= n; i++) {
    node *now = &matrix[i][0];
    while (now != nullptr) {
      if (now->value != INVALID) cout << now->value << " ";
      now = now->ptr[0];
    }
    cout << '\n';
  }
  return 0;
}