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;
  int x;
  int y;
};
node tab[2000006];
int n, m, q;
int v;
int a, b, c, d, h, w;
void zamien() {
  int x1, y1, x2, y2;
  x1 = y1 = x2 = y2 = 0;
  int p1, p2;
  p1 = 0;
  p2 = 0;
  for (int i = 0; i < (a - 1); ++i) {
    p1 = tab[p1].y;
    y1++;
  }
  for (int i = 0; i < (b - 1); ++i) {
    x1++;
    p1 = tab[p1].x;
  }
  for (int i = 0; i < (c - 1); ++i) {
    p2 = tab[p2].y;
    y2++;
  }
  for (int i = 0; i < (d - 1); ++i) {
    p2 = tab[p2].x;
    x2++;
  }
  int xp1, xp2;
  xp1 = p1;
  xp2 = p2;
  for (int i = 0; i < (w); ++i) {
    xp1 = tab[xp1].x;
    xp2 = tab[xp2].x;
    swap(tab[xp2].y, tab[xp1].y);
  }
  int yp1, yp2;
  yp1 = p1;
  yp2 = p2;
  for (int i = 0; i < (h); ++i) {
    yp1 = tab[yp1].y;
    yp2 = tab[yp2].y;
    swap(tab[yp1].x, tab[yp2].x);
  }
  for (int i = 0; i < (w); ++i) {
    yp1 = tab[yp1].x;
    yp2 = tab[yp2].x;
    swap(tab[yp1].y, tab[yp2].y);
  }
  for (int i = 0; i < (h); ++i) {
    xp1 = tab[xp1].y;
    xp2 = tab[xp2].y;
    swap(tab[xp2].x, tab[xp1].x);
  }
}
int ans[1003][1003];
int main() {
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 1; i <= (n); ++i) {
    for (int p = 1; p <= (m); ++p) {
      scanf("%d", &tab[i * (m + 2) + p].val);
      tab[i * (m + 2) + p].x = i * (m + 2) + p + 1;
      tab[i * (m + 2) + p].y = (i + 1) * (m + 2) + p;
    }
  }
  for (int i = 0; i <= (m); ++i) {
    tab[i].x = i + 1;
    tab[i].y = m + 2 + i;
    tab[(n + 1) * (m + 2) + i].x = (n + 1) * (m + 2) + i + 1;
  }
  for (int i = 0; i <= (n); ++i) {
    tab[i * (m + 2)].y = (i + 1) * (m + 2);
    tab[i * (m + 2)].x = i * (m + 2) + 1;
    tab[(i + 1) * (m + 2) - 1].y = (i + 2) * (m + 2) - 1;
  }
  int p1, p2;
  for (int i = 0; i < (q); ++i) {
    scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &h, &w);
    zamien();
  }
  p1 = 0;
  p2 = 0;
  for (int i = 1; i <= (n); ++i) {
    p1 = tab[p1].y;
    p2 = p1;
    for (int p = 1; p <= (m); ++p) {
      p2 = tab[p2].x;
      ans[i][p] = tab[p2].val;
      printf("%d ", ans[i][p]);
    }
    printf("\n");
  }
}