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;
int N, M, Q;
int dx[MAXN][MAXN];
int dy[MAXN][MAXN];
int A[MAXN][MAXN];
int ans[MAXN][MAXN];
pair<int, int> D[MAXN][MAXN], R[MAXN][MAXN];
pair<int, int> Select(int first, int second) {
  pair<int, int> ret = {0, 0};
  for (int i = (int)(0); i < (int)(second); ++i) ret = R[ret.first][ret.second];
  for (int i = (int)(0); i < (int)(first); ++i) ret = D[ret.first][ret.second];
  return ret;
}
vector<pair<pair<int, int>, pair<int, int>>> vecR, vecD;
void SwapRow(int x1, int y1, int x2, int y2, int len) {
  auto T1 = Select(x1, y1);
  auto T2 = Select(x2, y2);
  for (int i = (int)(0); i < (int)(len); ++i) {
    vecD.emplace_back(T1, D[T2.first][T2.second]);
    vecD.emplace_back(T2, D[T1.first][T1.second]);
    T1 = R[T1.first][T1.second];
    T2 = R[T2.first][T2.second];
  }
}
void SwapCol(int x1, int y1, int x2, int y2, int len) {
  auto T1 = Select(x1, y1);
  auto T2 = Select(x2, y2);
  for (int i = (int)(0); i < (int)(len); ++i) {
    swap(R[T1.first][T1.second], R[T2.first][T2.second]);
    T1 = D[T1.first][T1.second];
    T2 = D[T2.first][T2.second];
  }
}
void DoSwaps() {
  for (auto it : vecD) {
    auto t = it.first;
    D[t.first][t.second] = it.second;
  }
  vecD.clear();
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin >> N >> M >> Q;
  for (int i = (int)(1); i < (int)(N + 1); ++i)
    for (int j = (int)(1); j < (int)(M + 1); ++j) cin >> A[i][j];
  for (int i = (int)(0); i < (int)(N + 1); ++i)
    for (int j = (int)(0); j < (int)(M + 1); ++j) {
      D[i][j] = {i + 1, j};
      R[i][j] = {i, j + 1};
    }
  for (int i = (int)(0); i < (int)(Q); ++i) {
    int x1, x2, y1, y2, a, b;
    cin >> x1 >> y1 >> x2 >> y2 >> a >> b;
    SwapRow(x1 - 1, y1, x2 - 1, y2, b);
    SwapRow(x1 + a - 1, y1, x2 + a - 1, y2, b);
    SwapCol(x1, y1 - 1, x2, y2 - 1, a);
    SwapCol(x1, y1 + b - 1, x2, y2 + b - 1, a);
    DoSwaps();
  }
  for (int j = (int)(1); j < (int)(M + 1); ++j) {
    auto T = Select(1, j);
    for (int i = (int)(1); i < (int)(N + 1); ++i) {
      ans[i][j] = A[T.first][T.second];
      T = D[T.first][T.second];
    }
  }
  for (int i = (int)(1); i < (int)(N + 1); ++i)
    for (int j = (int)(1); j < (int)(M + 1); ++j)
      cout << ans[i][j] << " \n"[j == M];
  return 0;
}