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 RD {
  int ri, rj, di, dj, val;
} a[1001][1001];
int n, m, t, T, lx, ly, rx, ry, hi, wi;
int Ix, Iy, Jx, Jy, Ix2, Jx2, Iy2, Jy2;
int main() {
  scanf("%d%d%d", &n, &m, &T);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j].val);
      a[i][j].di = i + 1;
      a[i][j].dj = j;
      a[i][j].ri = i;
      a[i][j].rj = j + 1;
    }
  for (int i = 1; i <= m; i++)
    a[0][i].di = 1, a[0][i].dj = i, a[0][i].ri = 0, a[0][i].rj = i + 1;
  for (int i = 1; i <= n; i++)
    a[i][0].ri = i, a[i][0].rj = 1, a[i][0].di = i + 1, a[i][0].dj = 0;
  while (T--) {
    scanf("%d%d%d%d%d%d", &lx, &ly, &rx, &ry, &hi, &wi);
    Ix = lx, Jx = 0;
    for (int i = 1; i <= ly - 1; i++) {
      t = a[Ix][Jx].ri;
      Jx = a[Ix][Jx].rj;
      Ix = t;
    }
    Iy = rx, Jy = 0;
    for (int i = 1; i <= ry - 1; i++) {
      t = a[Iy][Jy].ri;
      Jy = a[Iy][Jy].rj;
      Iy = t;
    }
    Ix2 = Ix, Jx2 = Jx;
    for (int i = 1; i <= wi; i++) {
      t = a[Ix][Jx].ri;
      Jx = a[Ix][Jx].rj;
      Ix = t;
    }
    Iy2 = Iy, Jy2 = Jy;
    for (int i = 1; i <= wi; i++) {
      t = a[Iy][Jy].ri;
      Jy = a[Iy][Jy].rj;
      Iy = t;
    }
    for (int i = 1; i <= hi; i++) {
      swap(a[Ix][Jx].ri, a[Iy][Jy].ri);
      swap(a[Ix][Jx].rj, a[Iy][Jy].rj);
      t = a[Ix][Jx].di;
      Jx = a[Ix][Jx].dj;
      Ix = t;
      t = a[Iy][Jy].di;
      Jy = a[Iy][Jy].dj;
      Iy = t;
      swap(a[Ix2][Jx2].ri, a[Iy2][Jy2].ri);
      swap(a[Ix2][Jx2].rj, a[Iy2][Jy2].rj);
      t = a[Ix2][Jx2].di;
      Jx2 = a[Ix2][Jx2].dj;
      Ix2 = t;
      t = a[Iy2][Jy2].di;
      Jy2 = a[Iy2][Jy2].dj;
      Iy2 = t;
    }
    Ix = 0, Jx = ly;
    for (int i = 1; i <= lx - 1; i++) {
      t = a[Ix][Jx].di;
      Jx = a[Ix][Jx].dj;
      Ix = t;
    }
    Iy = 0, Jy = ry;
    for (int i = 1; i <= rx - 1; i++) {
      t = a[Iy][Jy].di;
      Jy = a[Iy][Jy].dj;
      Iy = t;
    }
    Ix2 = Ix, Jx2 = Jx;
    for (int i = 1; i <= hi; i++) {
      t = a[Ix][Jx].di;
      Jx = a[Ix][Jx].dj;
      Ix = t;
    }
    Iy2 = Iy, Jy2 = Jy;
    for (int i = 1; i <= hi; i++) {
      t = a[Iy][Jy].di;
      Jy = a[Iy][Jy].dj;
      Iy = t;
    }
    for (int i = 1; i <= wi; i++) {
      swap(a[Ix][Jx].di, a[Iy][Jy].di);
      swap(a[Ix][Jx].dj, a[Iy][Jy].dj);
      t = a[Ix][Jx].ri;
      Jx = a[Ix][Jx].rj;
      Ix = t;
      t = a[Iy][Jy].ri;
      Jy = a[Iy][Jy].rj;
      Iy = t;
      swap(a[Ix2][Jx2].di, a[Iy2][Jy2].di);
      swap(a[Ix2][Jx2].dj, a[Iy2][Jy2].dj);
      t = a[Ix2][Jx2].ri;
      Jx2 = a[Ix2][Jx2].rj;
      Ix2 = t;
      t = a[Iy2][Jy2].ri;
      Jy2 = a[Iy2][Jy2].rj;
      Iy2 = t;
    }
  }
  for (int i = 1; i <= n; i++) {
    int I = i, J = 0;
    for (int j = 1; j <= m; j++) {
      t = a[I][J].ri;
      J = a[I][J].rj;
      I = t;
      printf("%d ", a[I][J].val);
    }
    puts("");
  }
}