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 = 1050;
const int M = 1e4 + 50;
struct Node {
  int left;
  int right;
  int up;
  int down;
  int e;
};
struct Query {
  int a;
  int b;
  int c;
  int d;
  int h;
  int w;
};
Node node[N * N];
Query q[M];
int main() {
  int n, m, qNum, i, j, k, v, a, b, c, d, h, w, s1, s2, p1, p2, tmp;
  scanf("%d%d%d", &n, &m, &qNum);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      scanf("%d", &v);
      node[i * (m + 2) + j].e = v;
    }
  }
  for (i = 0; i < (n + 2) * (m + 2); i++) {
    node[i].left = i - 1;
    node[i].right = i + 1;
    node[i].up = i - (m + 2);
    node[i].down = i + (m + 2);
  }
  for (i = 0; i < qNum; i++) {
    scanf("%d%d%d%d%d%d", &q[i].a, &q[i].b, &q[i].c, &q[i].d, &q[i].h, &q[i].w);
  }
  for (k = 0; k < qNum; k++) {
    a = q[k].a;
    b = q[k].b;
    c = q[k].c;
    d = q[k].d;
    h = q[k].h;
    w = q[k].w;
    for (i = 1, s1 = node[1].down; i < a; i++, s1 = node[s1].down)
      ;
    for (j = 1; j < b; j++, s1 = node[s1].right)
      ;
    for (i = 1, s2 = node[1].down; i < c; i++, s2 = node[s2].down)
      ;
    for (j = 1; j < d; j++, s2 = node[s2].right)
      ;
    for (i = 1, p1 = s1, p2 = s2; i <= h;
         i++, p1 = node[p1].down, p2 = node[p2].down) {
      tmp = node[p1].left;
      node[p1].left = node[p2].left;
      node[node[p1].left].right = p1;
      node[p2].left = tmp;
      node[tmp].right = p2;
    }
    for (j = 1, p1 = s1, p2 = s2; j <= w;
         j++, p1 = node[p1].right, p2 = node[p2].right) {
      tmp = node[p1].up;
      node[p1].up = node[p2].up;
      node[node[p2].up].down = p1;
      node[p2].up = tmp;
      node[tmp].down = p2;
    }
    for (i = 1; i < h; i++, s1 = node[s1].down, s2 = node[s2].down)
      ;
    for (j = 1; j < w; j++, s1 = node[s1].right, s2 = node[s2].right)
      ;
    for (i = h, p1 = s1, p2 = s2; i >= 1;
         i--, p1 = node[p1].up, p2 = node[p2].up) {
      tmp = node[p1].right;
      node[p1].right = node[p2].right;
      node[node[p1].right].left = p1;
      node[p2].right = tmp;
      node[tmp].left = p2;
    }
    for (j = w, p1 = s1, p2 = s2; j >= 1;
         j--, p1 = node[p1].left, p2 = node[p2].left) {
      tmp = node[p1].down;
      node[p1].down = node[p2].down;
      node[node[p1].down].up = p1;
      node[p2].down = tmp;
      node[tmp].up = p2;
    }
  }
  for (i = 1; i <= n; i++) {
    p1 = node[i * (m + 2)].right;
    for (j = 1; j <= m; j++, p1 = node[p1].right) {
      printf("%d ", node[p1].e);
    }
    printf("\n");
  }
  return 0;
}