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 da {
  int val;
  pair<int, int> up;
  pair<int, int> dn;
  pair<int, int> l;
  pair<int, int> r;
} a[1007][1007];
int b[1007][1007];
int main() {
  int m, p, d;
  scanf("%d %d %d", &m, &p, &d);
  int i, j;
  for (i = 0; i <= m + 1; i++)
    for (j = 0; j <= p + 1; j++) {
      if (i && j && i <= m && j <= p) scanf("%d", &a[i][j].val);
      a[i][j].up = make_pair(i - 1, j), a[i][j].dn = make_pair(i + 1, j),
      a[i][j].r = make_pair(i, j + 1), a[i][j].l = make_pair(i, j - 1);
    }
  for (i = 0; i < d; i++) {
    int fr, fc, tr, tc, b, l;
    scanf("%d %d %d %d %d %d", &fr, &fc, &tr, &tc, &b, &l);
    pair<int, int> cur = make_pair(fr, 0);
    for (j = 0; j < fc; j++) cur = a[cur.first][cur.second].r;
    pair<int, int> curr = make_pair(tr, 0);
    for (j = 0; j < tc; j++) curr = a[curr.first][curr.second].r;
    for (j = 0; j < l - 1; j++) {
      a[(a[cur.first][cur.second].up).first]
       [(a[cur.first][cur.second].up).second]
           .dn = curr;
      a[(a[curr.first][curr.second].up).first]
       [(a[curr.first][curr.second].up).second]
           .dn = cur;
      swap(a[cur.first][cur.second].up, a[curr.first][curr.second].up);
      cur = a[cur.first][cur.second].r;
      curr = a[curr.first][curr.second].r;
    }
    a[(a[cur.first][cur.second].up).first][(a[cur.first][cur.second].up).second]
        .dn = curr;
    a[(a[curr.first][curr.second].up).first]
     [(a[curr.first][curr.second].up).second]
         .dn = cur;
    swap(a[cur.first][cur.second].up, a[curr.first][curr.second].up);
    for (j = 0; j < b - 1; j++) {
      a[(a[cur.first][cur.second].r).first][(a[cur.first][cur.second].r).second]
          .l = curr;
      a[(a[curr.first][curr.second].r).first]
       [(a[curr.first][curr.second].r).second]
           .l = cur;
      swap(a[cur.first][cur.second].r, a[curr.first][curr.second].r);
      cur = a[cur.first][cur.second].dn;
      curr = a[curr.first][curr.second].dn;
    }
    a[(a[cur.first][cur.second].r).first][(a[cur.first][cur.second].r).second]
        .l = curr;
    a[(a[curr.first][curr.second].r).first]
     [(a[curr.first][curr.second].r).second]
         .l = cur;
    swap(a[cur.first][cur.second].r, a[curr.first][curr.second].r);
    for (j = 0; j < l - 1; j++) {
      a[(a[cur.first][cur.second].dn).first]
       [(a[cur.first][cur.second].dn).second]
           .up = curr;
      a[(a[curr.first][curr.second].dn).first]
       [(a[curr.first][curr.second].dn).second]
           .up = cur;
      swap(a[cur.first][cur.second].dn, a[curr.first][curr.second].dn);
      cur = a[cur.first][cur.second].l;
      curr = a[curr.first][curr.second].l;
    }
    a[(a[cur.first][cur.second].dn).first][(a[cur.first][cur.second].dn).second]
        .up = curr;
    a[(a[curr.first][curr.second].dn).first]
     [(a[curr.first][curr.second].dn).second]
         .up = cur;
    swap(a[cur.first][cur.second].dn, a[curr.first][curr.second].dn);
    for (j = 0; j < b - 1; j++) {
      a[(a[cur.first][cur.second].l).first][(a[cur.first][cur.second].l).second]
          .r = curr;
      a[(a[curr.first][curr.second].l).first]
       [(a[curr.first][curr.second].l).second]
           .r = cur;
      swap(a[cur.first][cur.second].l, a[curr.first][curr.second].l);
      cur = a[cur.first][cur.second].up;
      curr = a[curr.first][curr.second].up;
    }
    a[(a[cur.first][cur.second].l).first][(a[cur.first][cur.second].l).second]
        .r = curr;
    a[(a[curr.first][curr.second].l).first]
     [(a[curr.first][curr.second].l).second]
         .r = cur;
    swap(a[cur.first][cur.second].l, a[curr.first][curr.second].l);
  }
  pair<int, int> cur = a[1][0].r;
  int lt = 0;
  for (i = 1; i <= m; i++) {
    if (!(lt % 2))
      j = 1;
    else
      j = p;
    if (!(lt % 2)) {
      while (j < p) {
        b[i][j] = a[cur.first][cur.second].val;
        j++;
        cur = a[cur.first][cur.second].r;
      }
      b[i][j] = a[cur.first][cur.second].val;
    } else {
      while (j > 1) {
        b[i][j] = a[cur.first][cur.second].val;
        j--;
        cur = a[cur.first][cur.second].l;
      }
      b[i][j] = a[cur.first][cur.second].val;
    }
    lt++;
    cur = a[cur.first][cur.second].dn;
  }
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= p; j++) printf("%d ", b[i][j]);
    printf("\n");
  }
  return 0;
}