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 MAXN = 1010;
struct node {
  node *up, *dn, *lt, *rt;
  int v;
  int x, y;
};
void setup(node *n, node *t) {
  if (t == NULL) {
    n->up->dn = NULL;
    n->up = NULL;
  } else {
    n->up = t;
    t->dn = n;
  }
}
void setdn(node *n, node *t) {
  if (t == NULL) {
    n->dn->up = NULL;
    n->dn = NULL;
  } else {
    n->dn = t;
    t->up = n;
  }
}
void setlt(node *n, node *t) {
  if (t == NULL) {
    n->lt->rt = NULL;
    n->lt = NULL;
  } else {
    n->lt = t;
    t->rt = n;
  }
}
void setrt(node *n, node *t) {
  if (t == NULL) {
    n->rt->lt = NULL;
    n->rt = NULL;
  } else {
    n->rt = t;
    t->lt = n;
  }
}
int N, M, Q;
node A[MAXN][MAXN];
node *at(int x, int y) {
  node *n = A[0];
  for (int i = 0; i < x; i++) {
    n = n->dn;
  }
  for (int j = 0; j < y; j++) {
    n = n->rt;
  }
  return n;
}
pair<node *, vector<node *> > cut(int a, int b, int h, int w) {
  node *ab = at(a, b);
  vector<node *> ans;
  for (int i = 0; i < h; i++) {
    ans.push_back(ab->lt);
    if (i != h - 1) {
      ab = ab->dn;
    }
  }
  for (int j = 0; j < w; j++) {
    ans.push_back(ab->dn);
    if (j != w - 1) {
      ab = ab->rt;
    }
  }
  for (int i = 0; i < h; i++) {
    ans.push_back(ab->rt);
    if (i != h - 1) {
      ab = ab->up;
    }
  }
  for (int j = 0; j < w; j++) {
    ans.push_back(ab->up);
    if (j != w - 1) {
      ab = ab->lt;
    }
  }
  return make_pair(ab, ans);
}
void link(node *n, vector<node *> v, int h, int w) {
  int ptr = 0;
  for (int i = 0; i < h; i++) {
    setlt(n, v[ptr++]);
    if (i != h - 1) {
      n = n->dn;
    }
  }
  for (int j = 0; j < w; j++) {
    setdn(n, v[ptr++]);
    if (j != w - 1) {
      n = n->rt;
    }
  }
  for (int i = 0; i < h; i++) {
    setrt(n, v[ptr++]);
    if (i != h - 1) {
      n = n->up;
    }
  }
  for (int j = 0; j < w; j++) {
    setup(n, v[ptr++]);
    if (j != w - 1) {
      n = n->lt;
    }
  }
}
int main() {
  scanf("%d %d %d", &N, &M, &Q);
  for (int i = 0; i <= N + 1; i++) {
    for (int j = 0; j <= M + 1; j++) {
      A[i][j].x = i;
      A[i][j].y = j;
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      scanf("%d", &A[i][j].v);
    }
  }
  for (int i = 0; i <= N + 1; i++) {
    for (int j = 0; j <= M; j++) {
      setrt(A[i] + j, A[i] + j + 1);
    }
  }
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M + 1; j++) {
      setdn(A[i] + j, A[i + 1] + j);
    }
  }
  while (Q--) {
    int a, b, c, d, h, w;
    scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &h, &w);
    auto nab = cut(a, b, h, w);
    auto ncd = cut(c, d, h, w);
    link(nab.first, ncd.second, h, w);
    link(ncd.first, nab.second, h, w);
  }
  node *n = A[0];
  for (int i = 1; i <= N; i++) {
    n = n->dn;
    node *nj = n;
    for (int j = 1; j <= M; j++) {
      nj = nj->rt;
      printf("%d ", nj->v);
    }
    puts("");
  }
}