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;
class value {
 public:
  int num, nextxx, nextxy, nextyx, nextyy;
  value() : num(0), nextxx(-1), nextxy(-1), nextyx(-1), nextyy(-1) {}
  void swap_down(value& other) {
    swap(nextxx, other.nextxx);
    swap(nextxy, other.nextxy);
  }
  void swap_right(value& other) {
    swap(nextyx, other.nextyx);
    swap(nextyy, other.nextyy);
  }
};
vector<vector<value> > v;
void right(int& x, int& y) {
  int nx = v[x][y].nextyx, ny = v[x][y].nextyy;
  x = nx;
  y = ny;
}
void down(int& x, int& y) {
  int nx = v[x][y].nextxx, ny = v[x][y].nextxy;
  x = nx;
  y = ny;
}
void get(int& x, int& y, int nx, int ny) {
  for (int i = 0; i < ny; i++) right(x, y);
  for (int i = 0; i < nx; i++) down(x, y);
}
void vypis(int n, int m) {
  vector<pair<int, int> > p(m + 1);
  p[0] = {0, 0};
  for (int i = 1; i <= m; i++) {
    p[i] = p[i - 1];
    right(p[i].first, p[i].second);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      down(p[j].first, p[j].second);
      cout << v[p[j].first][p[j].second].num << " ";
    }
    cout << "\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, q;
  cin >> n >> m >> q;
  v.resize(n + 1, vector<value>(m + 1));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> v[i + 1][j + 1].num;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (i < n) {
        v[i][j].nextxx = i + 1;
        v[i][j].nextxy = j;
      }
      if (j < m) {
        v[i][j].nextyx = i;
        v[i][j].nextyy = j + 1;
      }
    }
  }
  while (q--) {
    int x1, y1, x2, y2, h, w;
    cin >> x1 >> y1 >> x2 >> y2 >> h >> w;
    vector<pair<int, int> > p11(w), p21(w), p12(h), p22(h), p13(w), p23(w),
        p14(h), p24(h);
    get(p11[0].first, p11[0].second, x1 - 1, y1);
    get(p21[0].first, p21[0].second, x2 - 1, y2);
    get(p12[0].first, p12[0].second, x1, y1 - 1);
    get(p22[0].first, p22[0].second, x2, y2 - 1);
    get(p13[0].first, p13[0].second, x1 + h - 1, y1);
    get(p23[0].first, p23[0].second, x2 + h - 1, y2);
    get(p14[0].first, p14[0].second, x1, y1 + w - 1);
    get(p24[0].first, p24[0].second, x2, y2 + w - 1);
    for (int i = 1; i < w; i++) {
      p11[i] = p11[i - 1];
      right(p11[i].first, p11[i].second);
      p21[i] = p21[i - 1];
      right(p21[i].first, p21[i].second);
      p13[i] = p13[i - 1];
      right(p13[i].first, p13[i].second);
      p23[i] = p23[i - 1];
      right(p23[i].first, p23[i].second);
    }
    for (int i = 1; i < h; i++) {
      p12[i] = p12[i - 1];
      down(p12[i].first, p12[i].second);
      p22[i] = p22[i - 1];
      down(p22[i].first, p22[i].second);
      p14[i] = p14[i - 1];
      down(p14[i].first, p14[i].second);
      p24[i] = p24[i - 1];
      down(p24[i].first, p24[i].second);
    }
    for (int i = 0; i < w; i++) {
      v[p11[i].first][p11[i].second].swap_down(v[p21[i].first][p21[i].second]);
      v[p13[i].first][p13[i].second].swap_down(v[p23[i].first][p23[i].second]);
    }
    for (int i = 0; i < h; i++) {
      v[p12[i].first][p12[i].second].swap_right(v[p22[i].first][p22[i].second]);
      v[p14[i].first][p14[i].second].swap_right(v[p24[i].first][p24[i].second]);
    }
  }
  vypis(n, m);
  return 0;
}