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 int INF32 = 1E9;
const long long INF64 = 4E18;
const long long M = 1E9 + 7;
const double EPS = 1E-9;
const double PI = 2 * acos(0);
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (T x : p) os << x << " ";
  os << "]" << '\n';
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "{ ";
  for (T x : p) os << x << " ";
  os << "}" << '\n';
  return os;
}
template <typename Tk, typename Tv>
ostream& operator<<(ostream& os, const map<Tk, Tv>& p) {
  os << "{ ";
  for (pair<Tk, Tv> x : p) os << x << " ";
  os << "}" << '\n';
  return os;
}
template <typename Tk, typename Tv>
ostream& operator<<(ostream& os, const pair<Tk, Tv>& p) {
  os << "{" << p.first << ',' << p.second << "}";
  return os;
}
struct cell {
  int x = 0;
  int id = -1;
  int u = 0, l = 0, d = 0, r = 0;
  cell() {}
  friend ostream& operator<<(ostream& os, cell c) { return os << c.x; }
};
int crawl(int root, int r, int c, vector<cell>& pool) {
  int curr = root;
  for (int i = 0; i < r; ++i) {
    curr = pool[curr].d;
  }
  for (int i = 0; i < c; ++i) {
    curr = pool[curr].r;
  }
  return curr;
}
void print_matrix(int root, int n, int m, const vector<cell>& pool) {
  int ptr1 = root;
  for (int i = 0; i < n; ++i) {
    ptr1 = pool[ptr1].d;
    int ptr2 = ptr1;
    for (int j = 0; j < m; ++j) {
      ptr2 = pool[ptr2].r;
      cout << pool[ptr2].x << " ";
    }
    cout << '\n';
  }
}
bool is_valid(int i, int j, int n, int m) {
  return i >= 0 and j >= 0 and i <= n + 1 and j <= m + 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  if (fopen("tupni.txt", "r")) {
    freopen("tupni.txt", "r", stdin);
    freopen("tuptuo.txt", "w", stdout);
  }
  int n, m, q;
  cin >> n >> m >> q;
  vector<vector<cell>> cells(n + 2, vector<cell>(m + 2));
  int cnt = 0;
  for (int i = 0; i <= n + 1; ++i) {
    for (int j = 0; j <= m + 1; ++j) {
      cells[i][j].id = cnt++;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      int x;
      cin >> x;
      cells[i][j].x = x;
      cells[i][j].d = cells[i + 1][j].id;
      cells[i][j].u = cells[i - 1][j].id;
      cells[i][j].r = cells[i][j + 1].id;
      cells[i][j].l = cells[i][j - 1].id;
    }
  }
  for (int i = 0; i <= n + 1; ++i) {
    for (int j = 0; j <= m + 1; ++j) {
      if (is_valid(i + 1, j, n, m)) cells[i][j].d = cells[i + 1][j].id;
      if (is_valid(i - 1, j, n, m)) cells[i][j].u = cells[i - 1][j].id;
      if (is_valid(i, j + 1, n, m)) cells[i][j].r = cells[i][j + 1].id;
      if (is_valid(i, j - 1, n, m)) cells[i][j].l = cells[i][j - 1].id;
    }
  }
  vector<cell> pool((n + 2) * (m + 2));
  cnt = 0;
  for (int i = 0; i <= n + 1; ++i) {
    for (int j = 0; j <= m + 1; ++j) {
      pool[cnt++] = cells[i][j];
    }
  }
  int root = cells[0][0].id;
  while (q--) {
    int a, b, c, d, h, w;
    cin >> a >> b >> c >> d >> h >> w;
    int root1 = crawl(root, a, b, pool);
    int root2 = crawl(root, c, d, pool);
    int ptr1 = root1;
    int ptr2 = root2;
    for (int i = 0; i < h; ++i) {
      int left1 = pool[ptr1].l;
      int left2 = pool[ptr2].l;
      pool[ptr1].l = left2;
      pool[ptr2].l = left1;
      pool[left1].r = ptr2;
      pool[left2].r = ptr1;
      if (i != h - 1) {
        ptr1 = pool[ptr1].d;
        ptr2 = pool[ptr2].d;
      }
    }
    for (int i = 0; i < w; ++i) {
      int down1 = pool[ptr1].d;
      int down2 = pool[ptr2].d;
      pool[ptr1].d = down2;
      pool[ptr2].d = down1;
      pool[down1].u = ptr2;
      pool[down2].u = ptr1;
      if (i != w - 1) {
        ptr1 = pool[ptr1].r;
        ptr2 = pool[ptr2].r;
      }
    }
    for (int i = 0; i < h; ++i) {
      int right1 = pool[ptr1].r;
      int right2 = pool[ptr2].r;
      pool[ptr1].r = right2;
      pool[ptr2].r = right1;
      pool[right1].l = ptr2;
      pool[right2].l = ptr1;
      if (i != h - 1) {
        ptr1 = pool[ptr1].u;
        ptr2 = pool[ptr2].u;
      }
    }
    for (int i = 0; i < w; ++i) {
      int up1 = pool[ptr1].u;
      int up2 = pool[ptr2].u;
      pool[ptr1].u = up2;
      pool[ptr2].u = up1;
      pool[up1].d = ptr2;
      pool[up2].d = ptr1;
      if (i != w - 1) {
        ptr1 = pool[ptr1].l;
        ptr2 = pool[ptr2].l;
      }
    }
  }
  print_matrix(root, n, m, pool);
  return 0;
}