#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();   }