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 N = 1e3 + 5;
const long long INF = 1e16;
const int K = 32;
int mx[N][N];
int ans[N][N];
pair<int, int> r[N][N];
pair<int, int> down[N][N];
int n, m, q;
pair<int, int> real(pair<int, int> q) {
  pair<int, int> t = make_pair(0, 0);
  for (int i = 0; i < q.first; i++) {
    t = down[t.first][t.second];
  }
  for (int j = 0; j < q.second; j++) {
    t = r[t.first][t.second];
  }
  return t;
}
int main() {
  scanf(" %d %d %d", &n, &m, &q);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf(" %d", &mx[i][j]);
    }
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      r[i][j] = make_pair(i, j + 1);
      down[i][j] = make_pair(i + 1, j);
    }
  }
  for (int i = 0; i < q; i++) {
    int a, b;
    int c, d;
    int h, w;
    scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &h, &w);
    pair<int, int> q1 = real(make_pair(a - 1, b));
    pair<int, int> q2 = real(make_pair(c - 1, d));
    pair<int, int> q3 = real(make_pair(a + h - 1, b));
    pair<int, int> q4 = real(make_pair(c + h - 1, d));
    for (int j = 0; j < w; j++) {
      swap(down[q1.first][q1.second], down[q2.first][q2.second]);
      swap(down[q3.first][q3.second], down[q4.first][q4.second]);
      q1 = r[q1.first][q1.second];
      q2 = r[q2.first][q2.second];
      q3 = r[q3.first][q3.second];
      q4 = r[q4.first][q4.second];
    }
    pair<int, int> p1 = real(make_pair(a, b - 1));
    pair<int, int> p2 = real(make_pair(c, d - 1));
    pair<int, int> p3 = real(make_pair(a, b + w - 1));
    pair<int, int> p4 = real(make_pair(c, d + w - 1));
    for (int j = 0; j < h; j++) {
      swap(r[p1.first][p1.second], r[p2.first][p2.second]);
      swap(r[p3.first][p3.second], r[p4.first][p4.second]);
      p1 = down[p1.first][p1.second];
      p2 = down[p2.first][p2.second];
      p3 = down[p3.first][p3.second];
      p4 = down[p4.first][p4.second];
    }
  }
  pair<int, int> t = make_pair(0, 0);
  for (int i = 0; i <= n; i++) {
    pair<int, int> nt = t;
    for (int j = 0; j <= m; j++) {
      ans[i][j] = mx[nt.first][nt.second];
      nt = r[nt.first][nt.second];
    }
    t = down[t.first][t.second];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      printf("%d ", ans[i][j]);
    }
    printf("\n");
  }
  return 0;
}