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 leave {
  int value;
  int right;
  int lower;
};
leave build() {
  leave l;
  l.value = -1;
  l.right = -1;
  l.lower = -1;
  return l;
};
int r(const vector<leave> &a, int n, int l) {
  leave point = a[n];
  int num = n;
  for (int i = 0; i < l; ++i) {
    num = point.right;
    point = a[point.right];
  }
  return num;
}
int d(const vector<leave> &a, int n, int l) {
  leave point = a[n];
  int num = n;
  for (int i = 0; i < l; ++i) {
    num = point.lower;
    point = a[point.lower];
  }
  return num;
}
int go_to(const vector<leave> &a, int x, int y) {
  int temp = r(a, 0, x);
  return d(a, temp, y);
}
void change(vector<leave> &a, int x1, int y1, int x2, int y2, int w, int h) {
  int i11 = go_to(a, x1 - 1, y1 - 1), i12 = go_to(a, x2 - 1, y2 - 1);
  int i21 = go_to(a, x1 - 1, y1 - 1), i22 = go_to(a, x2 - 1, y2 - 1);
  int i31 = go_to(a, x1 - 1, y1 + h - 1), i32 = go_to(a, x2 - 1, y2 + h - 1);
  int i41 = go_to(a, x1 + w - 1, y1 - 1), i42 = go_to(a, x2 + w - 1, y2 - 1);
  for (int i = 0; i < w; ++i) {
    i11 = r(a, i11, 1);
    i12 = r(a, i12, 1);
    int temp = a[i11].lower;
    a[i11].lower = a[i12].lower;
    a[i12].lower = temp;
  }
  for (int i = 0; i < h; ++i) {
    i21 = d(a, i21, 1);
    i22 = d(a, i22, 1);
    int temp = a[i21].right;
    a[i21].right = a[i22].right;
    a[i22].right = temp;
  }
  for (int i = 0; i < w; ++i) {
    i31 = r(a, i31, 1);
    i32 = r(a, i32, 1);
    int temp = a[i31].lower;
    a[i31].lower = a[i32].lower;
    a[i32].lower = temp;
  }
  for (int i = 0; i < h; ++i) {
    i41 = d(a, i41, 1);
    i42 = d(a, i42, 1);
    int temp = a[i41].right;
    a[i41].right = a[i42].right;
    a[i42].right = temp;
  }
}
void print(const vector<leave> a, int n, int m) {
  for (int i = 1; i <= n; ++i) {
    int t = go_to(a, 0, i);
    for (int j = 1; j <= m; ++j) {
      t = r(a, t, 1);
      cout << a[t].value << " ";
    }
    cout << endl;
  }
}
int main() {
  int n, m, q, i, j;
  cin >> n >> m >> q;
  vector<int> x1(q), y1(q), x2(q), y2(q), w(q), h(q);
  vector<vector<int> > A(n + 2);
  for (i = 0; i < n + 2; ++i) A[i].resize(m + 2);
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= m; ++j) {
      cin >> A[i][j];
    }
  }
  for (i = 0; i < q; ++i) {
    cin >> y1[i] >> x1[i] >> y2[i] >> x2[i] >> h[i] >> w[i];
  }
  for (i = 0; i < n + 2; ++i) {
    for (j = 0; j < m + 2; ++j) {
      if (i == 0 || j == 0 || i == n + 1 || j == m + 1) A[i][j] = -1;
    }
  }
  vector<leave> a((m + 2) * (n + 2));
  for (i = 0; i < n + 2; ++i) {
    for (j = 0; j < m + 2; ++j) {
      a[(m + 2) * i + j].value = A[i][j];
    }
  }
  for (i = 0; i < n + 2; ++i) {
    for (j = 0; j < m + 2; ++j) {
      if (i != n + 1) {
        a[(m + 2) * i + j].lower = (m + 2) * i + j + m + 2;
      } else
        a[(m + 2) * i + j].lower = -1;
      if (j != m + 1) {
        a[(m + 2) * i + j].right = (m + 2) * i + j + 1;
      } else
        a[(m + 2) * i + j].right = -1;
    }
  }
  for (i = 0; i < q; ++i) {
    change(a, x1[i], y1[i], x2[i], y2[i], w[i], h[i]);
  }
  print(a, n, m);
  return 0;
}