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 celula {
  int val;
  struct celula *stanga, *sus, *dreapta, *jos;
};
typedef struct celula* celula_t;
celula_t primu;
celula_t adresa(int, int);
int main() {
  int n, m, q;
  scanf("%d %d %d", &n, &m, &q);
  int i, j;
  celula_t temp = NULL;
  celula_t sus = (celula_t)malloc(sizeof(struct celula));
  sus->stanga = NULL;
  sus->sus = NULL;
  sus->dreapta = NULL;
  sus->jos = NULL;
  sus->val = 0;
  temp = sus;
  for (i = 0; i <= m; ++i) {
    celula_t nou = (celula_t)malloc(sizeof(struct celula));
    nou->stanga = temp;
    nou->sus = NULL;
    nou->dreapta = NULL;
    nou->jos = NULL;
    nou->val = 0;
    temp->dreapta = nou;
    temp = nou;
  }
  celula_t stanga = (celula_t)malloc(sizeof(struct celula));
  stanga->stanga = NULL;
  stanga->sus = sus;
  sus->jos = stanga;
  stanga->dreapta = NULL;
  stanga->jos = NULL;
  stanga->val = 0;
  temp = stanga;
  for (i = 0; i <= n; ++i) {
    celula_t nou = (celula_t)malloc(sizeof(struct celula));
    nou->stanga = NULL;
    nou->sus = temp;
    nou->dreapta = NULL;
    nou->jos = NULL;
    nou->val = 0;
    temp->jos = nou;
    temp = nou;
  }
  sus = sus->dreapta;
  celula_t stanga_t = stanga;
  celula_t sus_t = sus;
  celula_t celula_noua;
  primu = sus;
  for (i = 0; i < n; ++i) {
    if (i != 0) {
      stanga = stanga_t->jos;
      stanga_t = stanga;
      sus = sus_t->jos;
      sus_t = sus;
    }
    for (j = 0; j < m; ++j) {
      int val;
      scanf("%d", &val);
      celula_noua = (celula_t)malloc(sizeof(struct celula));
      celula_noua->val = val;
      celula_noua->stanga = stanga;
      celula_noua->sus = sus;
      celula_noua->dreapta = NULL;
      celula_noua->jos = NULL;
      stanga->dreapta = celula_noua;
      sus->jos = celula_noua;
      if (i + 1 == n) {
        celula_noua->jos = (celula_t)malloc(sizeof(struct celula));
        celula_noua->jos->sus = celula_noua;
        celula_noua->jos->stanga = stanga->jos;
        stanga->jos->dreapta = celula_noua->jos;
        celula_noua->jos->dreapta = NULL;
        celula_noua->jos->jos = NULL;
        celula_noua->jos->val = 0;
      }
      stanga = stanga->dreapta;
      sus = sus->dreapta;
    }
    celula_noua->dreapta = (celula_t)malloc(sizeof(struct celula));
    celula_noua->dreapta->sus = sus;
    sus->jos = celula_noua->dreapta;
    celula_noua->dreapta->stanga = celula_noua;
    celula_noua->dreapta->dreapta = NULL;
    celula_noua->dreapta->jos = NULL;
    celula_noua->dreapta->val = 0;
  }
  celula_noua = (celula_t)malloc(sizeof(struct celula));
  celula_noua->jos = NULL;
  celula_noua->dreapta = NULL;
  celula_noua->stanga = stanga->jos;
  stanga->jos->dreapta = celula_noua;
  celula_noua->sus = stanga->dreapta;
  stanga->dreapta->jos = celula_noua;
  celula_noua->val = 0;
  primu = primu->stanga;
  temp = primu;
  for (; q > 0; --q) {
    int x1, y1, x2, y2, h, l;
    scanf("%d %d %d %d %d %d", &x1, &y1, &x2, &y2, &h, &l);
    celula_t start1 = adresa(x1, y1);
    celula_t start2 = adresa(x2, y2);
    int v;
    v = 0;
    celula_t sus1 = start1->sus;
    celula_t sus2 = start2->sus;
    while (v < l) {
      celula_t pe_putin = sus1->jos;
      sus1->jos = sus2->jos;
      sus2->jos = pe_putin;
      sus1 = sus1->dreapta;
      sus2 = sus2->dreapta;
      pe_putin = start1->sus;
      start1->sus = start2->sus;
      start2->sus = pe_putin;
      start1 = start1->dreapta;
      start2 = start2->dreapta;
      ++v;
    }
    start1 = start1->stanga;
    start2 = start2->stanga;
    v = 0;
    celula_t dreapta1 = start1->dreapta;
    celula_t dreapta2 = start2->dreapta;
    while (v < h) {
      celula_t pe_putin = dreapta1->stanga;
      dreapta1->stanga = dreapta2->stanga;
      dreapta2->stanga = pe_putin;
      dreapta1 = dreapta1->jos;
      dreapta2 = dreapta2->jos;
      pe_putin = start1->dreapta;
      start1->dreapta = start2->dreapta;
      start2->dreapta = pe_putin;
      start1 = start1->jos;
      start2 = start2->jos;
      ++v;
    }
    start1 = start1->sus;
    start2 = start2->sus;
    v = 0;
    celula_t jos1 = start1->jos;
    celula_t jos2 = start2->jos;
    while (v < l) {
      celula_t pe_putin = jos1->sus;
      jos1->sus = jos2->sus;
      jos2->sus = pe_putin;
      jos1 = jos1->stanga;
      jos2 = jos2->stanga;
      pe_putin = start1->jos;
      start1->jos = start2->jos;
      start2->jos = pe_putin;
      start1 = start1->stanga;
      start2 = start2->stanga;
      ++v;
    }
    start1 = start1->dreapta;
    start2 = start2->dreapta;
    v = 0;
    celula_t stanga1 = start1->stanga;
    celula_t stanga2 = start2->stanga;
    while (v < h) {
      celula_t pe_putin = stanga1->dreapta;
      stanga1->dreapta = stanga2->dreapta;
      stanga2->dreapta = pe_putin;
      stanga1 = stanga1->sus;
      stanga2 = stanga2->sus;
      pe_putin = start1->stanga;
      start1->stanga = start2->stanga;
      start2->stanga = pe_putin;
      start1 = start1->sus;
      start2 = start2->sus;
      ++v;
    }
    start1 = start1->jos;
    start2 = start2->jos;
  }
  temp = primu->dreapta;
  for (i = 0; i < n; ++i) {
    temp = temp->jos;
    primu = temp;
    for (j = 0; j < m; ++j) {
      printf("%d ", primu->val);
      primu = primu->dreapta;
    }
    printf("\n");
  }
  return 0;
}
celula_t adresa(int x, int y) {
  int i, j;
  i = 0;
  j = 0;
  celula_t iterator = primu;
  while (i < x) {
    iterator = iterator->jos;
    i++;
  }
  while (j < y) {
    iterator = iterator->dreapta;
    j++;
  }
  return iterator;
}