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;
pair<int, int> ref_right[1002][1002];
pair<int, int> ref_down[1002][1002];
int dt[1002][1002];
void move_right(int& a, int& b) {
  pair<int, int> next = ref_right[a][b];
  int i = next.first;
  int j = next.second;
  a = i;
  b = j;
}
void move_down(int& a, int& b) {
  pair<int, int> next = ref_down[a][b];
  int i = next.first;
  int j = next.second;
  a = i;
  b = j;
}
pair<int, int> move_right(pair<int, int> p) {
  pair<int, int> next = ref_right[p.first][p.second];
  return next;
}
pair<int, int> move_down(pair<int, int> p) {
  pair<int, int> next = ref_down[p.first][p.second];
  return next;
}
pair<int, int> go(pair<int, int> p) {
  int i = 0;
  int j = 0;
  for (int _n = p.first, t = 0; t < _n; ++t) move_down(i, j);
  for (int _n = p.second, t = 0; t < _n; ++t) move_right(i, j);
  return make_pair(i, j);
}
pair<int, int> go(int a, int b) {
  int i = 0;
  int j = 0;
  for (int _n = a, t = 0; t < _n; ++t) move_down(i, j);
  for (int _n = b, t = 0; t < _n; ++t) move_right(i, j);
  return make_pair(i, j);
}
void change_stripes(int h, int w, vector<pair<int, int>>& o1,
                    vector<pair<int, int>>& l1, vector<pair<int, int>>& o2,
                    vector<pair<int, int>>& l2) {
  for (int cnt = 0; cnt < h; ++cnt) {
    int i1 = o1[cnt].first, j1 = o1[cnt].second;
    int i2 = l1[cnt].first, j2 = l1[cnt].second;
    ref_right[i1][j1] = make_pair(i2, j2);
  }
  for (int cnt = 0; cnt < w; ++cnt) {
    int i1 = o2[cnt].first, j1 = o2[cnt].second;
    int i2 = l2[cnt].first, j2 = l2[cnt].second;
    ref_down[i1][j1] = make_pair(i2, j2);
  }
}
void eval_down(int h, pair<int, int> p, vector<pair<int, int>>& r) {
  r.push_back(p);
  for (int _n = h - 1, i = 0; i < _n; ++i) {
    p = ref_down[p.first][p.second];
    r.push_back(p);
  }
}
void eval_right(int w, pair<int, int> p, vector<pair<int, int>>& r) {
  r.push_back(p);
  for (int _n = w - 1, i = 0; i < _n; ++i) {
    p = ref_right[p.first][p.second];
    r.push_back(p);
  }
}
int main(int argc, char* argv[]) {
  int n, m, q;
  scanf("%d %d %d", &n, &m, &q);
  for (int _n = n, i = 0; i < _n; ++i)
    for (int _n = m, j = 0; j < _n; ++j) scanf("%d", &dt[i][j]);
  for (int _n = n + 2, i = 0; i < _n; ++i) {
    for (int _n = m + 2, j = 0; j < _n; ++j) {
      ref_right[i][j] = make_pair(i, j + 1);
      ref_down[i][j] = make_pair(i + 1, j);
    }
  }
  vector<pair<int, int>> o1v, o2v;
  vector<pair<int, int>> l1v, l2v;
  vector<pair<int, int>> o_1v, o_2v;
  vector<pair<int, int>> l_1v, l_2v;
  vector<pair<int, int>> o__1v, o__2v;
  vector<pair<int, int>> l__1v, l__2v;
  vector<pair<int, int>> o___1v, o___2v;
  vector<pair<int, int>> l___1v, l___2v;
  o1v.reserve(1000), o2v.reserve(1000);
  l1v.reserve(1000), l2v.reserve(1000);
  o_1v.reserve(1000), o_2v.reserve(1000);
  l_1v.reserve(1000), l_2v.reserve(1000);
  o__1v.reserve(1000), o__2v.reserve(1000);
  l__1v.reserve(1000), l__2v.reserve(1000);
  o___1v.reserve(1000), o___2v.reserve(1000);
  l___1v.reserve(1000), l___2v.reserve(1000);
  for (int _n = q, p = 0; p < _n; ++p) {
    int a, b, c, d, h, w;
    scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &h, &w);
    --a;
    --b;
    --c;
    --d;
    int start1row = a + 1;
    int start1col = b + 1;
    int end1row = a + h;
    int end1col = b + w;
    int start2row = c + 1;
    int start2col = d + 1;
    int end2row = c + h;
    int end2col = d + w;
    pair<int, int> pab = go(a, b);
    pair<int, int> pcd = go(c, d);
    o1v.clear(), o2v.clear();
    l1v.clear(), l2v.clear();
    o_1v.clear(), o_2v.clear();
    l_1v.clear(), l_2v.clear();
    o__1v.clear(), o__2v.clear();
    l__1v.clear(), l__2v.clear();
    o___1v.clear(), o___2v.clear();
    l___1v.clear(), l___2v.clear();
    pair<int, int> o1 = move_down(pab);
    eval_down(h, o1, o1v);
    pair<int, int> l1 = move_down(move_right(pcd));
    eval_down(h, l1, l1v);
    pair<int, int> o2 = move_right(pab);
    eval_right(w, o2, o2v);
    pair<int, int> l2 = move_down(move_right(pcd));
    eval_right(w, l2, l2v);
    pair<int, int> o_1 = move_down(pcd);
    eval_down(h, o_1, o_1v);
    pair<int, int> l_1 = move_down(move_right(pab));
    eval_down(h, l_1, l_1v);
    pair<int, int> o_2 = move_right(pcd);
    eval_right(w, o_2, o_2v);
    pair<int, int> l_2 = move_down(move_right(pab));
    eval_right(w, l_2, l_2v);
    pair<int, int> p_s1r_e1c = go(start1row, end1col);
    pair<int, int> p_s2r_e2c = go(start2row, end2col);
    pair<int, int> o__1 = p_s1r_e1c;
    eval_down(h, o__1, o__1v);
    pair<int, int> l__1 = move_right(p_s2r_e2c);
    eval_down(h, l__1, l__1v);
    pair<int, int> o__2 = go(end1row, start1col);
    eval_right(w, o__2, o__2v);
    pair<int, int> l__2 = go(end2row + 1, start2col);
    eval_right(w, l__2, l__2v);
    pair<int, int> o___1 = p_s2r_e2c;
    eval_down(h, o___1, o___1v);
    pair<int, int> l___1 = move_right(p_s1r_e1c);
    eval_down(h, l___1, l___1v);
    pair<int, int> o___2 = go(end2row, start2col);
    eval_right(w, o___2, o___2v);
    pair<int, int> l___2 = go(end1row + 1, start1col);
    eval_right(w, l___2, l___2v);
    change_stripes(h, w, o1v, l1v, o2v, l2v);
    change_stripes(h, w, o_1v, l_1v, o_2v, l_2v);
    change_stripes(h, w, o__1v, l__1v, o__2v, l__2v);
    change_stripes(h, w, o___1v, l___1v, o___2v, l___2v);
  }
  for (int _n = n, a = 0; a < _n; ++a) {
    int i = a + 1, j = 0;
    int x = ref_right[i][j].first, y = ref_right[i][j].second;
    for (int _n = m, b = 0; b < _n; ++b) {
      printf("%d ", dt[x - 1][y - 1]);
      move_right(x, y);
    }
    printf("\n");
  }
}