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;
template <class T>
inline T bigmod(T p, T e, T M) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T bpow(T p, T e) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p);
    p = (p * p);
  }
  return (T)ret;
}
int toInt(string s) {
  int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
int toLlint(string s) {
  long long int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
int ts, kk = 1;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int a[1005][1005];
pair<int, int> nx[4][1005][1005];
void swp(int k, pair<int, int> q1, pair<int, int> q2) {
  swap(nx[k][q1.first][q1.second], nx[k][q2.first][q2.second]);
  q1 = nx[k][q1.first][q1.second];
  q2 = nx[k][q2.first][q2.second];
  k ^= 1;
  swap(nx[k][q1.first][q1.second], nx[k][q2.first][q2.second]);
}
int n, m;
int u, v, x, y, h, w;
pair<int, int> q1, q2;
int main() {
  int t, i, j, k;
  scanf("%d%d%d", &n, &m, &ts);
  for (i = 1; i < n + 1; i++) {
    for (j = 1; j < m + 1; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  for (i = 0; i < n + 2; i++)
    for (j = 0; j < m + 2; j++)
      for (k = 0; k < 4; k++)
        nx[k][i][j] = pair<int, int>(i + dx[k], j + dy[k]);
  while (ts--) {
    scanf("%d%d%d%d%d%d", &u, &v, &x, &y, &h, &w);
    q1 = pair<int, int>(u, 0);
    q2 = pair<int, int>(x, 0);
    for (j = 0; j < min(v, y); j++)
      q1 = nx[3][q1.first][q1.second], q2 = nx[3][q2.first][q2.second];
    for (k = j; k < v; k++) q1 = nx[3][q1.first][q1.second];
    for (k = j; k < y; k++) q2 = nx[3][q2.first][q2.second];
    for (i = 0; i < w; i++) {
      swp(0, q1, q2);
      if (i != w - 1)
        q1 = nx[3][q1.first][q1.second], q2 = nx[3][q2.first][q2.second];
    }
    for (i = 0; i < h; i++) {
      swp(3, q1, q2);
      if (i != h - 1)
        q1 = nx[1][q1.first][q1.second], q2 = nx[1][q2.first][q2.second];
    }
    for (i = 0; i < w; i++) {
      swp(1, q1, q2);
      if (i != w - 1)
        q1 = nx[2][q1.first][q1.second], q2 = nx[2][q2.first][q2.second];
    }
    for (i = 0; i < h; i++) {
      swp(2, q1, q2);
      if (i != h - 1)
        q1 = nx[0][q1.first][q1.second], q2 = nx[0][q2.first][q2.second];
    }
  }
  for (i = 1; i <= n; i++) {
    q1 = pair<int, int>(i, 0);
    bool g = 0;
    for (q1 = nx[3][q1.first][q1.second]; q1.second <= m;
         q1 = nx[3][q1.first][q1.second]) {
      if (g)
        printf(" %d", a[q1.first][q1.second]);
      else
        printf("%d", a[q1.first][q1.second]), g = 1;
    }
    puts("");
  }
  return 0;
}