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;
const long long INF = numeric_limits<int>::max();
const long long LINF = numeric_limits<long long>::max() / 2;
const double DINF = numeric_limits<double>::max();
const int ITER = 3000;
const double EPS = 1e-9;
const int MAXN = 1005;
struct addr {
  int x, y;
  addr(){};
  addr(int a, int b) {
    x = a;
    y = b;
  }
};
struct cell {
  addr top, bot, left, right;
  addr cur;
  cell(){};
};
cell a[MAXN][MAXN];
int val[MAXN][MAXN];
int getVal(addr cur) { return val[cur.x][cur.y]; }
cell moveLeft(cell x) {
  x = a[x.left.x][x.left.y];
  return x;
}
cell moveRight(cell x) {
  x = a[x.right.x][x.right.y];
  return x;
}
cell moveTop(cell x) {
  x = a[x.top.x][x.top.y];
  return x;
}
cell moveBot(cell x) {
  x = a[x.bot.x][x.bot.y];
  return x;
}
string strad(addr x) {
  stringstream ss;
  ss << "(" << x.x << ", " << x.y << ")";
  return ss.str();
}
void solve() {
  int n, m, q;
  cin >> n >> m >> q;
  for (int i = 0; i < MAXN; ++i) {
    for (int j = 0; j < MAXN; ++j) {
      a[i][j].cur.x = i;
      a[i][j].cur.y = j;
      if (i > 0) a[i][j].top = addr(i - 1, j);
      if (i < MAXN - 1) a[i][j].bot = addr(i + 1, j);
      if (j < MAXN - 1) a[i][j].right = addr(i, j + 1);
      if (j > 0) a[i][j].left = addr(i, j - 1);
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> val[i][j];
    }
  }
  cout << endl;
  cell it = a[0][0];
  while (q--) {
    int x, y, c, d, h, w;
    cin >> x >> y >> c >> d >> h >> w;
    cell first = a[0][0];
    cell second = a[0][0];
    for (int i = 0; i < x; ++i) first = moveBot(first);
    for (int i = 0; i < y; ++i) first = moveRight(first);
    for (int i = 0; i < c; ++i) second = moveBot(second);
    for (int i = 0; i < d; ++i) second = moveRight(second);
    for (int i = 0; i < w; ++i) {
      addr ftop = first.top;
      addr stop = second.top;
      a[ftop.x][ftop.y].bot = second.cur;
      a[stop.x][stop.y].bot = first.cur;
      a[first.cur.x][first.cur.y].top = stop;
      a[second.cur.x][second.cur.y].top = ftop;
      if (i < w - 1) {
        first = moveRight(first);
        second = moveRight(second);
      }
    }
    for (int i = 0; i < h; ++i) {
      addr fright = first.right;
      addr sright = second.right;
      a[fright.x][fright.y].left = second.cur;
      a[sright.x][sright.y].left = first.cur;
      a[first.cur.x][first.cur.y].right = sright;
      a[second.cur.x][second.cur.y].right = fright;
      if (i < h - 1) {
        first = moveBot(first);
        second = moveBot(second);
      }
    }
    for (int i = 0; i < w; ++i) {
      addr fbot = first.bot;
      addr sbot = second.bot;
      a[fbot.x][fbot.y].top = second.cur;
      a[sbot.x][sbot.y].top = first.cur;
      a[first.cur.x][first.cur.y].bot = sbot;
      a[second.cur.x][second.cur.y].bot = fbot;
      if (i < w - 1) {
        first = moveLeft(first);
        second = moveLeft(second);
      }
    }
    for (int i = 0; i < h; ++i) {
      addr sleft = second.left;
      addr fleft = first.left;
      a[fleft.x][fleft.y].right = second.cur;
      a[sleft.x][sleft.y].right = first.cur;
      a[first.cur.x][first.cur.y].left = sleft;
      a[second.cur.x][second.cur.y].left = fleft;
      if (i < h - 1) {
        first = moveTop(first);
        second = moveTop(second);
      }
    }
  }
  it = a[0][0];
  it = moveRight(it);
  it = moveBot(it);
  for (int i = 0; i < n; ++i) {
    cell col = it;
    for (int j = 0; j < m; ++j) {
      cout << getVal(col.cur) << ' ';
      col = moveRight(col);
    }
    it = moveBot(it);
    cout << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}