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;
inline int rd() {
  int x = 0, ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void rt(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10)
    rt(x / 10), putchar(x % 10 + '0');
  else
    putchar(x + '0');
}
const int maxn = 1005;
int n, m, q;
pair<int, int> d[maxn][maxn], r[maxn][maxn];
int v[maxn][maxn];
pair<int, int> tmp, tmp1, tmp2, mat11, mat12, mat21, mat22;
inline pair<int, int> find(int nx, int ny, int x, int y) {
  for (int i = 1; i <= int(x); i++)
    tmp = d[nx][ny], nx = tmp.first, ny = tmp.second;
  for (int i = 1; i <= int(y); i++)
    tmp = r[nx][ny], nx = tmp.first, ny = tmp.second;
  return make_pair(nx, ny);
}
int main() {
  n = rd(), m = rd(), q = rd();
  for (int i = 0; i <= int(n); i++)
    for (int j = 0; j <= int(m); j++)
      d[i][j] = make_pair(i + 1, j), r[i][j] = make_pair(i, j + 1);
  for (int i = 1; i <= int(n); i++)
    for (int j = 1; j <= int(m); j++) v[i][j] = rd();
  for (; q--;) {
    int x1 = rd(), orz_szj = rd(), x2 = rd(), orz_rxd = rd(), h = rd(),
        w = rd();
    mat11 = find(0, 0, x1 - 1, orz_szj - 1),
    mat21 = find(0, 0, x2 - 1, orz_rxd - 1);
    mat12 = r[mat11.first][mat11.second], mat22 = r[mat21.first][mat21.second];
    mat11 = d[mat11.first][mat11.second], mat21 = d[mat21.first][mat21.second];
    tmp1 = find(mat11.first, mat11.second, h - 1, 0),
    tmp2 = find(mat21.first, mat21.second, h - 1, 0);
    for (int i = 1; i <= int(w); i++) {
      tmp1 = r[tmp1.first][tmp1.second], tmp2 = r[tmp2.first][tmp2.second];
      swap(d[tmp1.first][tmp1.second], d[tmp2.first][tmp2.second]);
    }
    tmp1 = find(mat12.first, mat12.second, 0, w - 1),
    tmp2 = find(mat22.first, mat22.second, 0, w - 1);
    for (int i = 1; i <= int(h); i++) {
      tmp1 = d[tmp1.first][tmp1.second], tmp2 = d[tmp2.first][tmp2.second];
      swap(r[tmp1.first][tmp1.second], r[tmp2.first][tmp2.second]);
    }
    tmp1 = mat12, tmp2 = mat22;
    for (int i = 1; i <= int(w); i++) {
      swap(d[tmp1.first][tmp1.second], d[tmp2.first][tmp2.second]);
      tmp1 = r[tmp1.first][tmp1.second], tmp2 = r[tmp2.first][tmp2.second];
    }
    tmp1 = mat11, tmp2 = mat21;
    for (int i = 1; i <= int(h); i++) {
      swap(r[tmp1.first][tmp1.second], r[tmp2.first][tmp2.second]);
      tmp1 = d[tmp1.first][tmp1.second], tmp2 = d[tmp2.first][tmp2.second];
    }
  }
  pair<int, int> hs = make_pair(0, 0);
  for (int i = 1; i <= int(n); i++) {
    hs = d[hs.first][hs.second];
    tmp = hs;
    for (int j = 1; j <= int(m); j++)
      tmp = r[tmp.first][tmp.second], rt(v[tmp.first][tmp.second]),
      putchar(' ');
    putchar('\n');
  }
}