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>
struct request {
  int l0, l1, r0, r1, w0, w1;
};
struct matrix_item {
  int value;
  matrix_item* right;
  matrix_item* down;
  matrix_item() : value(0), right(nullptr), down(nullptr) {}
};
matrix_item* read_data(int& queries) {
  int n, m;
  scanf("%d%d%d", &n, &m, &queries);
  matrix_item* root = new matrix_item();
  matrix_item* tmp = root;
  for (int i = 1; i <= m; ++i) {
    tmp->right = new matrix_item();
    tmp = tmp->right;
  }
  matrix_item* prevRow = root;
  for (int i = 1; i <= n; ++i) {
    matrix_item* curRow = prevRow->down = new matrix_item();
    matrix_item* curRowStart = curRow;
    for (int j = 1; j <= m; ++j) {
      curRow->right = new matrix_item();
      curRow = curRow->right;
      prevRow = prevRow->right;
      prevRow->down = curRow;
      scanf("%d", &curRow->value);
    }
    prevRow = curRowStart;
  }
  return root;
}
request read_request() {
  request result{0, 0, 500, 500, 500, 500};
  scanf("%d%d%d%d%d%d", &result.l0, &result.l1, &result.r0, &result.r1,
        &result.w0, &result.w1);
  return result;
}
matrix_item* find_element(matrix_item* matrix, int r, int c) {
  matrix_item* node = matrix;
  for (int i = 1; i < r; ++i) {
    node = node->down;
  }
  for (int j = 1; j < c; ++j) {
    node = node->right;
  }
  return node;
}
void swap_next_row(matrix_item*& p0, matrix_item*& p1, int cnt) {
  for (int i = 0; i < cnt; ++i) {
    p0 = p0->right;
    p1 = p1->right;
    std::swap(p0->down, p1->down);
  }
}
void swap_next_col(matrix_item*& p0, matrix_item*& p1, int cnt) {
  for (int i = 0; i < cnt; ++i) {
    p0 = p0->down;
    p1 = p1->down;
    std::swap(p0->right, p1->right);
  }
}
void apply_request(matrix_item* matrix, const request& r) {
  matrix_item* lBefore = find_element(matrix, r.l0, r.l1);
  matrix_item* rBefore = find_element(matrix, r.r0, r.r1);
  matrix_item *tmpL = lBefore, *tmpR = rBefore;
  swap_next_row(tmpL, tmpR, r.w1);
  swap_next_col(tmpL, tmpR, r.w0);
  tmpL = lBefore, tmpR = rBefore;
  swap_next_col(tmpL, tmpR, r.w0);
  swap_next_row(tmpL, tmpR, r.w1);
}
void do_work(matrix_item* matrix, int queries) {
  for (int i = 0; i < queries; ++i) {
    request r = read_request();
    apply_request(matrix, r);
  }
}
void print(matrix_item* matrix) {
  bool is_row_printable = false;
  for (matrix_item* next_row; matrix != nullptr; matrix = next_row) {
    next_row = matrix->down;
    bool is_column_printable = false;
    for (matrix_item *node = matrix, *next; node != nullptr; node = next) {
      next = node->right;
      if (is_column_printable) {
        printf("%d ", node->value);
      }
      is_column_printable = is_row_printable;
    }
    if (is_row_printable) {
      printf("\n");
    }
    is_row_printable = true;
  }
}
int main() {
  int queries = 0;
  auto matrix = read_data(queries);
  do_work(matrix, queries);
  print(matrix);
  return 0;
}