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>
constexpr int N = 1100;
struct Point {
  int x, y;
};
struct Node {
  Point u, d, l, r;
} board[N][N];
int a, b, c, d, h, w;
int under[N][N];
int n, m;
void output() {
  for (int i = 1; i <= n; ++i) {
    int x = i, y = 0;
    for (int i = 0; i < m; ++i) {
      int nx = board[x][y].r.x;
      int ny = board[x][y].r.y;
      x = nx;
      y = ny;
      std::cout << under[x][y] << " \n"[i == m - 1];
    }
  }
}
void work() {
  int altx = a;
  int alty = 0;
  for (int i = 0; i < b; ++i) {
    int nx = board[altx][alty].r.x;
    int ny = board[altx][alty].r.y;
    altx = nx;
    alty = ny;
  }
  int bltx = c;
  int blty = 0;
  for (int i = 0; i < d; ++i) {
    int nx = board[bltx][blty].r.x;
    int ny = board[bltx][blty].r.y;
    bltx = nx;
    blty = ny;
  }
  for (int i = 0; i < h; ++i) {
    int alx = board[altx][alty].l.x;
    int aly = board[altx][alty].l.y;
    int blx = board[bltx][blty].l.x;
    int bly = board[bltx][blty].l.y;
    board[alx][aly].r.x = bltx;
    board[alx][aly].r.y = blty;
    board[blx][bly].r.x = altx;
    board[blx][bly].r.y = alty;
    board[altx][alty].l.x = blx;
    board[altx][alty].l.y = bly;
    board[bltx][blty].l.x = alx;
    board[bltx][blty].l.y = aly;
    if (i == h - 1) break;
    int adx = board[altx][alty].d.x;
    int ady = board[altx][alty].d.y;
    int bdx = board[bltx][blty].d.x;
    int bdy = board[bltx][blty].d.y;
    altx = adx;
    alty = ady;
    bltx = bdx;
    blty = bdy;
  }
  for (int i = 0; i < w; ++i) {
    int adx = board[altx][alty].d.x;
    int ady = board[altx][alty].d.y;
    int bdx = board[bltx][blty].d.x;
    int bdy = board[bltx][blty].d.y;
    board[adx][ady].u.x = bltx;
    board[adx][ady].u.y = blty;
    board[bdx][bdy].u.x = altx;
    board[bdx][bdy].u.y = alty;
    board[altx][alty].d.x = bdx;
    board[altx][alty].d.y = bdy;
    board[bltx][blty].d.x = adx;
    board[bltx][blty].d.y = ady;
    if (i == w - 1) break;
    int arx = board[altx][alty].r.x;
    int ary = board[altx][alty].r.y;
    int brx = board[bltx][blty].r.x;
    int bry = board[bltx][blty].r.y;
    altx = arx;
    alty = ary;
    bltx = brx;
    blty = bry;
  }
  for (int i = 0; i < h; ++i) {
    int arx = board[altx][alty].r.x;
    int ary = board[altx][alty].r.y;
    int brx = board[bltx][blty].r.x;
    int bry = board[bltx][blty].r.y;
    board[arx][ary].l.x = bltx;
    board[arx][ary].l.y = blty;
    board[brx][bry].l.x = altx;
    board[brx][bry].l.y = alty;
    board[altx][alty].r.x = brx;
    board[altx][alty].r.y = bry;
    board[bltx][blty].r.x = arx;
    board[bltx][blty].r.y = ary;
    if (i == h - 1) break;
    int aux = board[altx][alty].u.x;
    int auy = board[altx][alty].u.y;
    int bux = board[bltx][blty].u.x;
    int buy = board[bltx][blty].u.y;
    altx = aux;
    alty = auy;
    bltx = bux;
    blty = buy;
  }
  for (int i = 0; i < w; ++i) {
    int aux = board[altx][alty].u.x;
    int auy = board[altx][alty].u.y;
    int bux = board[bltx][blty].u.x;
    int buy = board[bltx][blty].u.y;
    board[aux][auy].d.x = bltx;
    board[aux][auy].d.y = blty;
    board[bux][buy].d.x = altx;
    board[bux][buy].d.y = alty;
    board[altx][alty].u.x = bux;
    board[altx][alty].u.y = buy;
    board[bltx][blty].u.x = aux;
    board[bltx][blty].u.y = auy;
    if (i == w - 1) break;
    int alx = board[altx][alty].l.x;
    int aly = board[altx][alty].l.y;
    int blx = board[bltx][blty].l.x;
    int bly = board[bltx][blty].l.y;
    altx = alx;
    alty = aly;
    bltx = blx;
    blty = bly;
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  int q;
  std::cin >> n >> m >> q;
  for (int i = 0; i <= n + 1; ++i) {
    for (int j = 0; j <= m + 1; ++j) {
      board[i][j].u.x = i - 1;
      board[i][j].u.y = j;
      board[i][j].d.x = i + 1;
      board[i][j].d.y = j;
      board[i][j].l.x = i;
      board[i][j].l.y = j - 1;
      board[i][j].r.x = i;
      board[i][j].r.y = j + 1;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      std::cin >> under[i][j];
    }
  }
  for (int i = 0; i < q; ++i) {
    std::cin >> a >> b >> c >> d >> h >> w;
    work();
  }
  output();
  return 0;
}