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 long long rd() {
  long long x = 0;
  int 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;
pair<int, int> tmp, tmp1, tmp2, tmp3, tmp4;
pair<int, int> d[maxn][maxn], l[maxn][maxn], r[maxn][maxn], u[maxn][maxn];
pair<int, int> find(int nx, int ny, int x, int y) {
  pair<int, int> tmp;
  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 n, m, q, v[maxn][maxn];
int main() {
  n = rd(), m = rd(), q = rd();
  for (int i = 1; i <= (int)n; i++)
    for (int j = 1; j <= (int)m; j++) v[i][j] = rd();
  for (int i = 0; i <= (int)n + 1; i++)
    for (int j = 0; j <= (int)m + 1; j++)
      l[i][j] = make_pair(i, j - 1), r[i][j] = make_pair(i, j + 1),
      u[i][j] = make_pair(i - 1, j), d[i][j] = make_pair(i + 1, j);
  for (; q--;) {
    int x1 = rd(), orz_szj = rd(), x2 = rd(), orz_rxd = rd(), h = rd(),
        w = rd();
    pair<int, int> mat1 = find(0, 0, x1, orz_szj),
                   mat2 = find(0, 0, x2, orz_rxd);
    tmp1 = mat1, tmp2 = mat2;
    for (int i = 0; i <= (int)h - 1; i++) {
      tmp3 = l[tmp1.first][tmp1.second], tmp4 = l[tmp2.first][tmp2.second];
      r[tmp3.first][tmp3.second] = tmp2, r[tmp4.first][tmp4.second] = tmp1;
      l[tmp1.first][tmp1.second] = tmp4, l[tmp2.first][tmp2.second] = tmp3;
      tmp1 = d[tmp1.first][tmp1.second], tmp2 = d[tmp2.first][tmp2.second];
    }
    tmp1 = mat1, tmp2 = mat2;
    for (int i = 0; i <= (int)w - 1; i++) {
      tmp3 = u[tmp1.first][tmp1.second], tmp4 = u[tmp2.first][tmp2.second];
      d[tmp3.first][tmp3.second] = tmp2, d[tmp4.first][tmp4.second] = tmp1;
      u[tmp1.first][tmp1.second] = tmp4, u[tmp2.first][tmp2.second] = tmp3;
      tmp1 = r[tmp1.first][tmp1.second], tmp2 = r[tmp2.first][tmp2.second];
    }
    tmp1 = find(mat1.first, mat1.second, 0, w - 1),
    tmp2 = find(mat2.first, mat2.second, 0, w - 1);
    for (int i = 0; i <= (int)h - 1; i++) {
      tmp3 = r[tmp1.first][tmp1.second], tmp4 = r[tmp2.first][tmp2.second];
      l[tmp3.first][tmp3.second] = tmp2, l[tmp4.first][tmp4.second] = tmp1;
      r[tmp1.first][tmp1.second] = tmp4, r[tmp2.first][tmp2.second] = tmp3;
      tmp1 = d[tmp1.first][tmp1.second], tmp2 = d[tmp2.first][tmp2.second];
    }
    tmp1 = find(mat1.first, mat1.second, h - 1, 0),
    tmp2 = find(mat2.first, mat2.second, h - 1, 0);
    for (int i = 0; i <= (int)w - 1; i++) {
      tmp3 = d[tmp1.first][tmp1.second], tmp4 = d[tmp2.first][tmp2.second];
      u[tmp3.first][tmp3.second] = tmp2, u[tmp4.first][tmp4.second] = tmp1;
      d[tmp1.first][tmp1.second] = tmp4, d[tmp2.first][tmp2.second] = tmp3;
      tmp1 = r[tmp1.first][tmp1.second], tmp2 = r[tmp2.first][tmp2.second];
    }
  }
  int nx = 0, ny = 0, x, y;
  for (int i = 1; i <= (int)n; i++) {
    tmp = d[nx][ny], nx = tmp.first, ny = tmp.second;
    x = nx, y = ny;
    for (int j = 1; j <= (int)m; j++) {
      tmp = r[x][y], x = tmp.first, y = tmp.second;
      rt(v[x][y]), putchar(' ');
    }
    putchar('\n');
  }
}