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 Cell {
  int val;
  Cell *neigh[4];
  Cell() {
    for (int i = 0; i < 4; ++i) neigh[i] = nullptr;
    val = 0;
  }
};
enum Dir { UP, RIGHT, DOWN, LEFT };
int di[4] = {-1, 0, 1, 0}, dj[4] = {0, 1, 0, -1};
int n, m, nrq;
Cell a[1005][1005];
Cell *border1[4][1005], *border2[4][1005], *topLeft;
bool inMatrix(int i, int j) {
  return 0 <= i && i <= n + 1 && 0 <= j && j <= m + 1;
}
Cell *getCell(int i, int j) {
  Cell *ans = topLeft;
  while (i--) ans = ans->neigh[DOWN];
  while (j--) ans = ans->neigh[RIGHT];
  return ans;
}
void getBorder(int i, int j, int n, int m, Cell *border[4][1005]) {
  Cell *x = getCell(i - 1, j);
  for (int jj = 1; jj <= m; ++jj) {
    border[0][jj] = x;
    x = x->neigh[RIGHT];
  }
  x = x->neigh[DOWN];
  for (int ii = 1; ii <= n; ++ii) {
    border[1][ii] = x;
    x = x->neigh[DOWN];
  }
  x = x->neigh[LEFT];
  for (int jj = m; jj >= 1; --jj) {
    border[2][jj] = x;
    x = x->neigh[LEFT];
  }
  x = x->neigh[UP];
  for (int ii = n; ii >= 1; --ii) {
    border[3][ii] = x;
    x = x->neigh[UP];
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &nrq);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) scanf("%d", &a[i][j].val);
  for (int i = 0; i <= n + 1; ++i) {
    for (int j = 0; j <= m + 1; ++j) {
      for (int d = 0; d < 4; ++d) {
        if (inMatrix(i + di[d], j + dj[d]))
          a[i][j].neigh[d] = &a[i + di[d]][j + dj[d]];
      }
    }
  }
  topLeft = &a[0][0];
  while (nrq--) {
    int i1, j1, i2, j2, nn, mm;
    scanf("%d %d %d %d %d %d", &i1, &j1, &i2, &j2, &nn, &mm);
    getBorder(i1, j1, nn, mm, border1);
    getBorder(i2, j2, nn, mm, border2);
    for (int i = 1; i <= nn; ++i) {
      Cell *aux = border1[LEFT][i]->neigh[RIGHT];
      border1[LEFT][i]->neigh[RIGHT] = border2[LEFT][i]->neigh[RIGHT];
      border2[LEFT][i]->neigh[RIGHT] = aux;
      border1[LEFT][i]->neigh[RIGHT]->neigh[LEFT] = border1[LEFT][i];
      border2[LEFT][i]->neigh[RIGHT]->neigh[LEFT] = border2[LEFT][i];
      aux = border1[RIGHT][i]->neigh[LEFT];
      border1[RIGHT][i]->neigh[LEFT] = border2[RIGHT][i]->neigh[LEFT];
      border2[RIGHT][i]->neigh[LEFT] = aux;
      border1[RIGHT][i]->neigh[LEFT]->neigh[RIGHT] = border1[RIGHT][i];
      border2[RIGHT][i]->neigh[LEFT]->neigh[RIGHT] = border2[RIGHT][i];
    }
    for (int j = 1; j <= mm; ++j) {
      Cell *aux = border1[UP][j]->neigh[DOWN];
      border1[UP][j]->neigh[DOWN] = border2[UP][j]->neigh[DOWN];
      border2[UP][j]->neigh[DOWN] = aux;
      border1[UP][j]->neigh[DOWN]->neigh[UP] = border1[UP][j];
      border2[UP][j]->neigh[DOWN]->neigh[UP] = border2[UP][j];
      aux = border1[DOWN][j]->neigh[UP];
      border1[DOWN][j]->neigh[UP] = border2[DOWN][j]->neigh[UP];
      border2[DOWN][j]->neigh[UP] = aux;
      border1[DOWN][j]->neigh[UP]->neigh[DOWN] = border1[DOWN][j];
      border2[DOWN][j]->neigh[UP]->neigh[DOWN] = border2[DOWN][j];
    }
  }
  Cell *lineStart = topLeft->neigh[DOWN]->neigh[RIGHT];
  for (int i = 1; i <= n;
       ++i, lineStart = lineStart->neigh[DOWN], printf("\n")) {
    Cell *x = lineStart;
    for (int j = 1; j <= m; ++j, x = x->neigh[RIGHT]) printf("%d ", x->val);
  }
  return 0;
}