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 N = 1005;
int n, m, mat[N][N], q;
struct Value {
  Value *up, *down, *left, *right;
  int v;
  Value(int x) {
    up = down = left = right = NULL;
    v = x;
  }
} * root[N], *Upx[N], *Upy[N], *Downx[N], *Downy[N], *Leftx[N], *Lefty[N],
    *Rightx[N], *Righty[N];
inline void Initialize() {
  for (int i = 1; i <= n; i++) {
    Value *tp;
    for (int j = 1; j <= m; j++) {
      if (j == 1) {
        root[i] = new Value(mat[i][j]);
        tp = root[i];
      } else {
        tp->right = new Value(mat[i][j]);
        tp->right->left = tp;
        tp = tp->right;
      }
    }
  }
}
inline void Build() {
  Value *tp[N];
  tp[0] = tp[n + 1] = NULL;
  for (int i = 1; i <= n; i++) tp[i] = root[i];
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      tp[j]->up = tp[j - 1];
      tp[j]->down = tp[j + 1];
    }
    for (int j = 1; j <= n; j++) tp[j] = tp[j]->right;
  }
}
inline void SelectX(Value *r[N], int x, int y, int len) {
  Value *tp = root[x];
  for (int i = 1; i < y; i++) tp = tp->right;
  for (int i = 1; i <= len; i++) {
    r[i] = tp;
    tp = tp->right;
  }
}
inline void SelectY(Value *r[N], int x, int y, int len) {
  Value *tp = root[x];
  for (int i = 1; i < y; i++) tp = tp->right;
  for (int i = 1; i <= len; i++) {
    r[i] = tp;
    tp = tp->down;
  }
}
inline void PrintMatrix() {
  for (int i = 1; i <= n; i++) {
    Value *cur;
    for (int j = 1; j <= m; j++) {
      if (j == 1)
        cur = root[i];
      else
        cur = cur->right;
      printf("%d ", cur->v);
    }
    putchar('\n');
  }
}
inline void Change(int l1, int r1, int l2, int r2, int h, int w) {
  Value *tp;
  SelectX(Upx, l1, r1, w);
  SelectX(Upy, l2, r2, w);
  SelectX(Downx, l1 + h - 1, r1, w);
  SelectX(Downy, l2 + h - 1, r2, w);
  SelectY(Leftx, l1, r1, h);
  SelectY(Lefty, l2, r2, h);
  SelectY(Rightx, l1, r1 + w - 1, h);
  SelectY(Righty, l2, r2 + w - 1, h);
  for (int i = 1; i <= h; i++) {
    if (Leftx[i]->left && Lefty[i]->left) {
      Leftx[i]->left->right = Lefty[i];
      Lefty[i]->left->right = Leftx[i];
      tp = Leftx[i]->left;
      Leftx[i]->left = Lefty[i]->left;
      Lefty[i]->left = tp;
    } else if (Leftx[i]->left && !Lefty[i]->left) {
      Lefty[i]->left = Leftx[i]->left;
      Leftx[i]->left->right = Lefty[i];
      Leftx[i]->left = NULL;
      root[l2 + i - 1] = Leftx[i];
    } else if (!Leftx[i]->left && Lefty[i]->left) {
      Leftx[i]->left = Lefty[i]->left;
      Lefty[i]->left->right = Leftx[i];
      Lefty[i]->left = NULL;
      root[l1 + i - 1] = Lefty[i];
    } else if (!Leftx[i]->left && !Lefty[i]->left) {
      root[l1 + i - 1] = Lefty[i];
      root[l2 + i - 1] = Leftx[i];
    }
    if (Rightx[i]->right && Righty[i]->right) {
      Rightx[i]->right->left = Righty[i];
      Righty[i]->right->left = Rightx[i];
      tp = Rightx[i]->right;
      Rightx[i]->right = Righty[i]->right;
      Righty[i]->right = tp;
    } else if (Rightx[i]->right && !Righty[i]->right) {
      Righty[i]->right = Rightx[i]->right;
      Rightx[i]->right->left = Righty[i];
      Rightx[i]->right = NULL;
    } else if (!Rightx[i]->right && Righty[i]->right) {
      Rightx[i]->right = Righty[i]->right;
      Righty[i]->right->left = Rightx[i];
      Righty[i]->right = NULL;
    }
  }
  for (int i = 1; i <= w; i++) {
    if (Upx[i]->up && Upy[i]->up) {
      Upx[i]->up->down = Upy[i];
      Upy[i]->up->down = Upx[i];
      tp = Upx[i]->up;
      Upx[i]->up = Upy[i]->up;
      Upy[i]->up = tp;
    } else if (Upx[i]->up && !Upy[i]->up) {
      Upx[i]->up->down = Upy[i];
      Upy[i]->up = Upx[i]->up;
      Upx[i]->up = NULL;
    } else if (!Upx[i]->up && Upy[i]->up) {
      Upx[i]->up = Upy[i]->up;
      Upy[i]->up->down = Upx[i];
      Upy[i]->up = NULL;
    }
    if (Downx[i]->down && Downy[i]->down) {
      Downx[i]->down->up = Downy[i];
      Downy[i]->down->up = Downx[i];
      tp = Downx[i]->down;
      Downx[i]->down = Downy[i]->down;
      Downy[i]->down = tp;
    } else if (Downx[i]->down && !Downy[i]->down) {
      Downy[i]->down = Downx[i]->down;
      Downx[i]->down->up = Downy[i];
      Downx[i]->down = NULL;
    } else if (!Downx[i]->down && Downy[i]->down) {
      Downx[i]->down = Downy[i]->down;
      Downy[i]->down->up = Downx[i];
      Downy[i]->down = NULL;
    }
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &mat[i][j]);
  Initialize();
  Build();
  while (q--) {
    int l1, r1, l2, r2, h, w;
    scanf("%d %d %d %d %d %d", &l1, &r1, &l2, &r2, &h, &w);
    Change(l1, r1, l2, r2, h, w);
  }
  PrintMatrix();
  return 0;
}