#pragma comment(linker, "/stack:20000000")
#define _CRT_SECURE_NO_WARNINGS
# include <iostream>
# include <cmath>
# include <algorithm>
# include <cstdio>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>

using namespace std;

// Let's define unordered map
# ifdef __GNUC__
# if __cplusplus > 199711L
# include <unordered_set>
# include <unordered_map>
# else
# include <tr1/unordered_map>
# include <tr1/unordered_set>
using namespace std::tr1;
# endif
# else
# include <unordered_map>
# include <unordered_set>
# endif

#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__, 5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,N,...) N
#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro, nargs) macro ## nargs
#define DBN1(a)         std::cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)       std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)     std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)   std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e) std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN(...) macro_dispatcher(DBN, __VA_ARGS__)(__VA_ARGS__)
#define DA(a,n) cout<<#a<<"=["; printarray(a,n); cout<<"]\n"
#define DAR(a,n,s) cout<<#a<<"["<<s<<"-"<<n-1<<"]=["; printarray(a,n,s); cout<<"]\n"

#ifdef _MSC_VER
#define ALIGN(x) __declspec(align(x))
#else
#define ALIGN(x) __attribute__((aligned(x)))
#endif

#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << std::endl
double __begin;
#define DTIME(ccc) __begin = clock(); ccc; std::cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<std::endl;

#define mp make_pair
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef int itn;

template<typename T1, typename T2, typename T3>
struct triple{ T1 a; T2 b; T3 c; triple() : a(T1()), b(T2()), c(T3()) {}; triple(T1 _a, T2 _b, T3 _c) :a(_a), b(_b), c(_c){} };
#define tri triple<int,int,int>
#define trll triple<ll,ll,ll>
template<typename T1, typename T2, typename T3>
bool operator<(const triple<T1, T2, T3> &t1, const triple<T1, T2, T3> &t2){ if (t1.a != t2.a) return t1.a<t2.a; else if (t1.b != t2.b) return t1.b<t2.b; else return t1.c < t2.c; }

#define FI(n) for(int i=0;i<n;++i)
#define FJ(n) for(int j=0;j<n;++j)
#define FK(n) for(int k=0;k<n;++k)
#define all(a) a.begin(), a.end()
//int some_primes[10] = {100271, 500179, 1000003, 2000227, 5000321}

inline int bits_count(int v){ v = v - ((v >> 1) & 0x55555555); v = (v & 0x33333333) + ((v >> 2) & 0x33333333); return((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; }
inline int bits_count(ll v){ int t = v >> 32; int p = (v & ((1LL << 32) - 1)); return bits_count(t) + bits_count(p); }
unsigned int reverse_bits(register unsigned int x){ x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1)); x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2)); x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4)); x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8)); return((x >> 16) | (x << 16)); }
inline int sign(int x){ return x > 0; }
inline bool isPowerOfTwo(int x){ return (x != 0 && (x&(x - 1)) == 0); }
#define checkbit(n, b) ((n >> b) & 1)
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())

//STL output ********************************
template<typename T1, typename T2> inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p);
template<typename T> inline std::ostream &operator<<(std::ostream &os, const std::vector<T>& v);
template<typename T>inline std::ostream &operator<<(std::ostream &os, const std::set<T>&v);
template<typename T1, typename T2>inline std::ostream &operator << (std::ostream & os, const std::map<T1, T2>& v);
template<typename T1, typename T2, typename T3> inline std::ostream& operator << (std::ostream& os, const triple<T1, T2, T3>& t);
template<typename T1, typename T2> inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p){ return os << "(" << p.first << ", " << p.second << ")"; }
template<typename T>inline std::ostream &operator<<(std::ostream &os, const std::vector<T>& v){ bool first = true; os << "["; for (unsigned int i = 0; i<v.size(); i++){ if (!first)os << ", "; os << v[i]; first = false; }return os << "]"; }
template<typename T>inline std::ostream &operator<<(std::ostream &os, const std::set<T>&v){ bool first = true; os << "["; for (auto ii = v.begin(); ii != v.end(); ++ii){ if (!first)os << ", "; os << *ii; first = false; }return os << "]"; }
template<typename T1, typename T2>inline std::ostream &operator << (std::ostream & os, const std::map<T1, T2>& v){ bool first = true; os << "["; for (auto ii = v.begin(); ii != v.end(); ++ii){ if (!first)os << ", "; os << *ii; first = false; }return os << "]"; }
template<typename T, typename T2>void printarray(T  a[], T2 sz, T2 beg = 0){ for (T2 i = beg; i<sz; i++) cout << a[i] << " "; cout << endl; }
template<typename T1, typename T2, typename T3>
inline std::ostream& operator << (std::ostream& os, const triple<T1, T2, T3>& t){ return os << "(" << t.a << ", " << t.b << ", " << t.c << ")"; }

//Pair magic
template<typename T1, typename T2> inline pair<T1, T2> operator+(const pair<T1, T2> &p1 , const pair<T1, T2> &p2) { return pair<T1, T2>(p1.first + p2.first, p1.second + p2.second); }
template<typename T1, typename T2> inline pair<T1, T2> operator-(const pair<T1, T2> &p1 , const pair<T1, T2> &p2) { return pair<T1, T2>(p1.first - p2.first, p1.second - p2.second); }

#define FREIN(FILE) freopen(FILE, "rt", stdin)
#define FREOUT(FILE) freopen(FILE, "wt", stdout)

#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(1.0 * (x))
#define pow(x, n) pow(1.0 * (x), n)

inline ll mulmod(ll x, ll n, ll _mod){ ll res = 0; while (n){ if (n & 1)res = (res + x) % _mod; x = (x + x) % _mod; n >>= 1; }return res; }
inline ll powmod(ll x, ll n, ll _mod){ ll res = 1; while (n){ if (n & 1)res = (res*x) % _mod; x = (x*x) % _mod; n >>= 1; }return res; }
inline ll gcd(ll a, ll b){ ll t; while (b){ a = a%b; t = a; a = b; b = t; }return a; }
inline int gcd(int a, int b){ int t; while (b){ a = a%b; t = a; a = b; b = t; }return a; }
inline ll lcm(ll a, ll b){ return a / gcd(a, b)*b; }
inline ll gcd(ll a, ll b, ll c){ return gcd(gcd(a, b), c); }
inline int gcd(int a, int b, int c){ return gcd(gcd(a, b), c); }

// Useful constants

#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define mod         1000000007
#define PI          3.14159265358979323
#define link        asaxlajrewqwe
#define rank        wahayawehasdakw
//*************************************************************************************

const int BUSFIZE = 4096;
int read_int() {
    static char inbuf[BUSFIZE + 16];
    static char* inp = inbuf;
    static char* linp = inbuf + BUSFIZE;
    if (*inp == 0) {
        cin.read(inbuf, BUSFIZE);
        inp = inbuf;
    }
    while (*inp && (*inp < '0' || *inp > '9'))
        ++inp;
    int res = 0;
    while (*inp >= '0' && *inp <= '9') {
        res = res * 10 + *inp - '0';
        ++inp;
        if (inp == linp) {
            cin.read(inbuf, BUSFIZE);
            inp = inbuf;
        }
    }
    ++inp;
    return res;
}
static char outbuf[BUSFIZE + 16];
static char *outptr = outbuf;
static char *loutp = outbuf + BUSFIZE;
void write_int(int x) {
    char* begp = outptr;
    while (x) {
        int t = x / 10;
        char c = x - 10 * t + '0';
        *outptr++ = c;
        x = t;
    }
    char* endp = outptr - 1;
    while (begp < endp) {
        swap(*begp, *endp);
        ++begp;
        --endp;
    }
    if (outptr > loutp) {
        cout.write(outbuf, outptr - outbuf);
        outptr = outbuf;
    }
    *outptr++ = ' ';
}

int x[1008][1008];
void swap(char *a, char *b, int n) {
    int t = n % 96;
    if (t) {
        char buffer[96];
        memcpy(buffer, a, t);
        memcpy(a, b, t);
        memcpy(b, buffer, t);
        a += t;
        b += t;
    }
    n /= 96;
    typedef __m128i* Ptr;
    Ptr ptra = (Ptr)a;
    Ptr ptrb = (Ptr)b;
    while (n--) {
        __m128i t0 = _mm_loadu_si128(ptra + 0);
        __m128i t1 = _mm_loadu_si128(ptra + 1);
        __m128i t2 = _mm_loadu_si128(ptra + 2);
        __m128i t3 = _mm_loadu_si128(ptra + 3);
        __m128i t4 = _mm_loadu_si128(ptra + 4);
        __m128i t5 = _mm_loadu_si128(ptra + 5);
        _mm_storeu_si128(ptra + 0, _mm_loadu_si128(ptrb + 0));
        _mm_storeu_si128(ptra + 1, _mm_loadu_si128(ptrb + 1));
        _mm_storeu_si128(ptra + 2, _mm_loadu_si128(ptrb + 2));
        _mm_storeu_si128(ptra + 3, _mm_loadu_si128(ptrb + 3));
        _mm_storeu_si128(ptra + 4, _mm_loadu_si128(ptrb + 4));
        _mm_storeu_si128(ptra + 5, _mm_loadu_si128(ptrb + 5));
        _mm_storeu_si128(ptrb + 0, t0);
        _mm_storeu_si128(ptrb + 1, t1);
        _mm_storeu_si128(ptrb + 2, t2);
        _mm_storeu_si128(ptrb + 3, t3);
        _mm_storeu_si128(ptrb + 4, t4);
        _mm_storeu_si128(ptrb + 5, t5);
        ptra += 6;
        ptrb += 6;
    }
}
int v[1008 * 1008];
char data[1008][3008];
int vs = 0;

int main() {
#ifdef LOCAL
    FREIN("in.txt");
    FREOUT("out.txt");
#endif
    ios_base::sync_with_stdio(0);
    int n, m, q;
    n = read_int();
    m = read_int();
    q = read_int();
    FI(n) FJ(m) {
        v[vs] = read_int();
        int val = vs++;
        char *ptr = data[i] + j * 3;
        const char* valPtr = (const char*)&val;
        ptr[0] = valPtr[0];
        ptr[1] = valPtr[1];
        ptr[2] = valPtr[2];
    }
    while (q--) {
        int a, b, c, d, w, h;
        a = read_int();
        b = read_int();
        c = read_int();
        d = read_int();
        h = read_int();
        w = read_int();
        --a; --b; --c; --d;
        for (int i = 0; i < h; ++i) {
            swap(data[a + i] + b * 3, data[c + i] + d * 3, w * 3);
        }
    }
    FI(n) {
        FJ(m) {
            int val = 0;
            const char *ptr = data[i] + j * 3;
            char* valPtr = (char*)&val;
            valPtr[0] = ptr[0];
            valPtr[1] = ptr[1];
            valPtr[2] = ptr[2];
            val = v[val];
            write_int(val);
        }
        *outptr++ = '\n';
    }
    cout.write(outbuf, outptr - outbuf);
    CURTIME();
    return 0;
}


#pragma comment(linker, "/stack:20000000")
#define _CRT_SECURE_NO_WARNINGS
# include <iostream>
# include <cmath>
# include <algorithm>
# include <cstdio>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>

using namespace std;

// Let's define unordered map
# ifdef __GNUC__
# if __cplusplus > 199711L
# include <unordered_set>
# include <unordered_map>
# else
# include <tr1/unordered_map>
# include <tr1/unordered_set>
using namespace std::tr1;
# endif
# else
# include <unordered_map>
# include <unordered_set>
# endif

#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__, 5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,N,...) N
#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro, nargs) macro ## nargs
#define DBN1(a)         std::cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)       std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)     std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)   std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e) std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN(...) macro_dispatcher(DBN, __VA_ARGS__)(__VA_ARGS__)
#define DA(a,n) cout<<#a<<"=["; printarray(a,n); cout<<"]\n"
#define DAR(a,n,s) cout<<#a<<"["<<s<<"-"<<n-1<<"]=["; printarray(a,n,s); cout<<"]\n"

#ifdef _MSC_VER
#define ALIGN(x) __declspec(align(x))
#else
#define ALIGN(x) __attribute__((aligned(x)))
#endif

#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << std::endl
double __begin;
#define DTIME(ccc) __begin = clock(); ccc; std::cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<std::endl;

#define mp make_pair
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef int itn;

template<typename T1, typename T2, typename T3>
struct triple{ T1 a; T2 b; T3 c; triple() : a(T1()), b(T2()), c(T3()) {}; triple(T1 _a, T2 _b, T3 _c) :a(_a), b(_b), c(_c){} };
#define tri triple<int,int,int>
#define trll triple<ll,ll,ll>
template<typename T1, typename T2, typename T3>
bool operator<(const triple<T1, T2, T3> &t1, const triple<T1, T2, T3> &t2){ if (t1.a != t2.a) return t1.a<t2.a; else if (t1.b != t2.b) return t1.b<t2.b; else return t1.c < t2.c; }

#define FI(n) for(int i=0;i<n;++i)
#define FJ(n) for(int j=0;j<n;++j)
#define FK(n) for(int k=0;k<n;++k)
#define all(a) a.begin(), a.end()
//int some_primes[10] = {100271, 500179, 1000003, 2000227, 5000321}

inline int bits_count(int v){ v = v - ((v >> 1) & 0x55555555); v = (v & 0x33333333) + ((v >> 2) & 0x33333333); return((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; }
inline int bits_count(ll v){ int t = v >> 32; int p = (v & ((1LL << 32) - 1)); return bits_count(t) + bits_count(p); }
unsigned int reverse_bits(register unsigned int x){ x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1)); x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2)); x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4)); x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8)); return((x >> 16) | (x << 16)); }
inline int sign(int x){ return x > 0; }
inline bool isPowerOfTwo(int x){ return (x != 0 && (x&(x - 1)) == 0); }
#define checkbit(n, b) ((n >> b) & 1)
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())

//STL output ********************************
template<typename T1, typename T2> inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p);
template<typename T> inline std::ostream &operator<<(std::ostream &os, const std::vector<T>& v);
template<typename T>inline std::ostream &operator<<(std::ostream &os, const std::set<T>&v);
template<typename T1, typename T2>inline std::ostream &operator << (std::ostream & os, const std::map<T1, T2>& v);
template<typename T1, typename T2, typename T3> inline std::ostream& operator << (std::ostream& os, const triple<T1, T2, T3>& t);
template<typename T1, typename T2> inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p){ return os << "(" << p.first << ", " << p.second << ")"; }
template<typename T>inline std::ostream &operator<<(std::ostream &os, const std::vector<T>& v){ bool first = true; os << "["; for (unsigned int i = 0; i<v.size(); i++){ if (!first)os << ", "; os << v[i]; first = false; }return os << "]"; }
template<typename T>inline std::ostream &operator<<(std::ostream &os, const std::set<T>&v){ bool first = true; os << "["; for (auto ii = v.begin(); ii != v.end(); ++ii){ if (!first)os << ", "; os << *ii; first = false; }return os << "]"; }
template<typename T1, typename T2>inline std::ostream &operator << (std::ostream & os, const std::map<T1, T2>& v){ bool first = true; os << "["; for (auto ii = v.begin(); ii != v.end(); ++ii){ if (!first)os << ", "; os << *ii; first = false; }return os << "]"; }
template<typename T, typename T2>void printarray(T  a[], T2 sz, T2 beg = 0){ for (T2 i = beg; i<sz; i++) cout << a[i] << " "; cout << endl; }
template<typename T1, typename T2, typename T3>
inline std::ostream& operator << (std::ostream& os, const triple<T1, T2, T3>& t){ return os << "(" << t.a << ", " << t.b << ", " << t.c << ")"; }

//Pair magic
template<typename T1, typename T2> inline pair<T1, T2> operator+(const pair<T1, T2> &p1 , const pair<T1, T2> &p2) { return pair<T1, T2>(p1.first + p2.first, p1.second + p2.second); }
template<typename T1, typename T2> inline pair<T1, T2> operator-(const pair<T1, T2> &p1 , const pair<T1, T2> &p2) { return pair<T1, T2>(p1.first - p2.first, p1.second - p2.second); }

#define FREIN(FILE) freopen(FILE, "rt", stdin)
#define FREOUT(FILE) freopen(FILE, "wt", stdout)

#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(1.0 * (x))
#define pow(x, n) pow(1.0 * (x), n)

inline ll mulmod(ll x, ll n, ll _mod){ ll res = 0; while (n){ if (n & 1)res = (res + x) % _mod; x = (x + x) % _mod; n >>= 1; }return res; }
inline ll powmod(ll x, ll n, ll _mod){ ll res = 1; while (n){ if (n & 1)res = (res*x) % _mod; x = (x*x) % _mod; n >>= 1; }return res; }
inline ll gcd(ll a, ll b){ ll t; while (b){ a = a%b; t = a; a = b; b = t; }return a; }
inline int gcd(int a, int b){ int t; while (b){ a = a%b; t = a; a = b; b = t; }return a; }
inline ll lcm(ll a, ll b){ return a / gcd(a, b)*b; }
inline ll gcd(ll a, ll b, ll c){ return gcd(gcd(a, b), c); }
inline int gcd(int a, int b, int c){ return gcd(gcd(a, b), c); }

// Useful constants

#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define mod         1000000007
#define PI          3.14159265358979323
#define link        asaxlajrewqwe
#define rank        wahayawehasdakw
//*************************************************************************************

const int BUSFIZE = 4096;
int read_int() {
    static char inbuf[BUSFIZE + 16];
    static char* inp = inbuf;
    static char* linp = inbuf + BUSFIZE;
    if (*inp == 0) {
        cin.read(inbuf, BUSFIZE);
        inp = inbuf;
    }
    while (*inp && (*inp < '0' || *inp > '9'))
        ++inp;
    int res = 0;
    while (*inp >= '0' && *inp <= '9') {
        res = res * 10 + *inp - '0';
        ++inp;
        if (inp == linp) {
            cin.read(inbuf, BUSFIZE);
            inp = inbuf;
        }
    }
    ++inp;
    return res;
}
static char outbuf[BUSFIZE + 16];
static char *outptr = outbuf;
static char *loutp = outbuf + BUSFIZE;
void write_int(int x) {
    char* begp = outptr;
    while (x) {
        int t = x / 10;
        char c = x - 10 * t + '0';
        *outptr++ = c;
        x = t;
    }
    char* endp = outptr - 1;
    while (begp < endp) {
        swap(*begp, *endp);
        ++begp;
        --endp;
    }
    if (outptr > loutp) {
        cout.write(outbuf, outptr - outbuf);
        outptr = outbuf;
    }
    *outptr++ = ' ';
}

int x[1008][1008];
void swap(char *a, char *b, int n) {
    char buffer[3008];
    memmove(buffer, a, n);
    memmove(a, b, n);
    memmove(b, buffer, n);
    return;
    int t = n % 64;
    if (t) {
        memcpy(buffer, a, t);
        memcpy(a, b, t);
        memcpy(b, buffer, t);
        a += t;
        b += t;
    }
    n /= 64;
    typedef __m128i* Ptr;
    Ptr ptra = (Ptr)a;
    Ptr ptrb = (Ptr)b;
    while (n--) {
        __m128i t0 = _mm_loadu_si128(ptra + 0);
        __m128i t1 = _mm_loadu_si128(ptra + 1);
        __m128i t2 = _mm_loadu_si128(ptra + 2);
        __m128i t3 = _mm_loadu_si128(ptra + 3);
        _mm_storeu_si128(ptra + 0, _mm_loadu_si128(ptrb + 0));
        _mm_storeu_si128(ptra + 1, _mm_loadu_si128(ptrb + 1));
        _mm_storeu_si128(ptra + 2, _mm_loadu_si128(ptrb + 2));
        _mm_storeu_si128(ptra + 3, _mm_loadu_si128(ptrb + 3));
        _mm_storeu_si128(ptrb + 0, t0);
        _mm_storeu_si128(ptrb + 1, t1);
        _mm_storeu_si128(ptrb + 2, t2);
        _mm_storeu_si128(ptrb + 3, t3);
        ptra += 4;
        ptrb += 4;
    }
}
int v[1008 * 1008];
char data[1008][3008];
int vs = 0;

int main() {
#ifdef LOCAL
    FREIN("in.txt");
    FREOUT("out.txt");
#endif
    ios_base::sync_with_stdio(0);
    int n, m, q;
    n = read_int();
    m = read_int();
    q = read_int();
    FI(n) FJ(m) {
        v[vs] = read_int();
        int val = vs++;
        char *ptr = data[i] + j * 3;
        const char* valPtr = (const char*)&val;
        ptr[0] = valPtr[0];
        ptr[1] = valPtr[1];
        ptr[2] = valPtr[2];
    }
    while (q--) {
        int a, b, c, d, w, h;
        a = read_int();
        b = read_int();
        c = read_int();
        d = read_int();
        h = read_int();
        w = read_int();
        --a; --b; --c; --d;
        for (int i = 0; i < h; ++i) {
            swap(data[a + i] + b * 3, data[c + i] + d * 3, w * 3);
        }
    }
    FI(n) {
        FJ(m) {
            int val = 0;
            const char *ptr = data[i] + j * 3;
            char* valPtr = (char*)&val;
            valPtr[0] = ptr[0];
            valPtr[1] = ptr[1];
            valPtr[2] = ptr[2];
            val = v[val];
            write_int(val);
        }
        *outptr++ = '\n';
    }
    cout.write(outbuf, outptr - outbuf);
    CURTIME();
    return 0;
}


#pragma comment(linker, "/stack:20000000")
#define _CRT_SECURE_NO_WARNINGS
# include <iostream>
# include <cmath>
# include <algorithm>
# include <cstdio>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>

using namespace std;

// Let's define unordered map
# ifdef __GNUC__
# if __cplusplus > 199711L
# include <unordered_set>
# include <unordered_map>
# else
# include <tr1/unordered_map>
# include <tr1/unordered_set>
using namespace std::tr1;
# endif
# else
# include <unordered_map>
# include <unordered_set>
# endif

#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__, 5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,N,...) N
#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro, nargs) macro ## nargs
#define DBN1(a)         std::cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)       std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)     std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)   std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e) std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN(...) macro_dispatcher(DBN, __VA_ARGS__)(__VA_ARGS__)
#define DA(a,n) cout<<#a<<"=["; printarray(a,n); cout<<"]\n"
#define DAR(a,n,s) cout<<#a<<"["<<s<<"-"<<n-1<<"]=["; printarray(a,n,s); cout<<"]\n"

#ifdef _MSC_VER
#define ALIGN(x) __declspec(align(x))
#else
#define ALIGN(x) __attribute__((aligned(x)))
#endif

#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << std::endl
double __begin;
#define DTIME(ccc) __begin = clock(); ccc; std::cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<std::endl;

#define mp make_pair
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef int itn;

template<typename T1, typename T2, typename T3>
struct triple{ T1 a; T2 b; T3 c; triple() : a(T1()), b(T2()), c(T3()) {}; triple(T1 _a, T2 _b, T3 _c) :a(_a), b(_b), c(_c){} };
#define tri triple<int,int,int>
#define trll triple<ll,ll,ll>
template<typename T1, typename T2, typename T3>
bool operator<(const triple<T1, T2, T3> &t1, const triple<T1, T2, T3> &t2){ if (t1.a != t2.a) return t1.a<t2.a; else if (t1.b != t2.b) return t1.b<t2.b; else return t1.c < t2.c; }

#define FI(n) for(int i=0;i<n;++i)
#define FJ(n) for(int j=0;j<n;++j)
#define FK(n) for(int k=0;k<n;++k)
#define all(a) a.begin(), a.end()
//int some_primes[10] = {100271, 500179, 1000003, 2000227, 5000321}

inline int bits_count(int v){ v = v - ((v >> 1) & 0x55555555); v = (v & 0x33333333) + ((v >> 2) & 0x33333333); return((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; }
inline int bits_count(ll v){ int t = v >> 32; int p = (v & ((1LL << 32) - 1)); return bits_count(t) + bits_count(p); }
unsigned int reverse_bits(register unsigned int x){ x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1)); x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2)); x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4)); x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8)); return((x >> 16) | (x << 16)); }
inline int sign(int x){ return x > 0; }
inline bool isPowerOfTwo(int x){ return (x != 0 && (x&(x - 1)) == 0); }
#define checkbit(n, b) ((n >> b) & 1)
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())

//STL output ********************************
template<typename T1, typename T2> inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p);
template<typename T> inline std::ostream &operator<<(std::ostream &os, const std::vector<T>& v);
template<typename T>inline std::ostream &operator<<(std::ostream &os, const std::set<T>&v);
template<typename T1, typename T2>inline std::ostream &operator << (std::ostream & os, const std::map<T1, T2>& v);
template<typename T1, typename T2, typename T3> inline std::ostream& operator << (std::ostream& os, const triple<T1, T2, T3>& t);
template<typename T1, typename T2> inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p){ return os << "(" << p.first << ", " << p.second << ")"; }
template<typename T>inline std::ostream &operator<<(std::ostream &os, const std::vector<T>& v){ bool first = true; os << "["; for (unsigned int i = 0; i<v.size(); i++){ if (!first)os << ", "; os << v[i]; first = false; }return os << "]"; }
template<typename T>inline std::ostream &operator<<(std::ostream &os, const std::set<T>&v){ bool first = true; os << "["; for (auto ii = v.begin(); ii != v.end(); ++ii){ if (!first)os << ", "; os << *ii; first = false; }return os << "]"; }
template<typename T1, typename T2>inline std::ostream &operator << (std::ostream & os, const std::map<T1, T2>& v){ bool first = true; os << "["; for (auto ii = v.begin(); ii != v.end(); ++ii){ if (!first)os << ", "; os << *ii; first = false; }return os << "]"; }
template<typename T, typename T2>void printarray(T  a[], T2 sz, T2 beg = 0){ for (T2 i = beg; i<sz; i++) cout << a[i] << " "; cout << endl; }
template<typename T1, typename T2, typename T3>
inline std::ostream& operator << (std::ostream& os, const triple<T1, T2, T3>& t){ return os << "(" << t.a << ", " << t.b << ", " << t.c << ")"; }

//Pair magic
template<typename T1, typename T2> inline pair<T1, T2> operator+(const pair<T1, T2> &p1 , const pair<T1, T2> &p2) { return pair<T1, T2>(p1.first + p2.first, p1.second + p2.second); }
template<typename T1, typename T2> inline pair<T1, T2> operator-(const pair<T1, T2> &p1 , const pair<T1, T2> &p2) { return pair<T1, T2>(p1.first - p2.first, p1.second - p2.second); }

#define FREIN(FILE) freopen(FILE, "rt", stdin)
#define FREOUT(FILE) freopen(FILE, "wt", stdout)

#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(1.0 * (x))
#define pow(x, n) pow(1.0 * (x), n)

inline ll mulmod(ll x, ll n, ll _mod){ ll res = 0; while (n){ if (n & 1)res = (res + x) % _mod; x = (x + x) % _mod; n >>= 1; }return res; }
inline ll powmod(ll x, ll n, ll _mod){ ll res = 1; while (n){ if (n & 1)res = (res*x) % _mod; x = (x*x) % _mod; n >>= 1; }return res; }
inline ll gcd(ll a, ll b){ ll t; while (b){ a = a%b; t = a; a = b; b = t; }return a; }
inline int gcd(int a, int b){ int t; while (b){ a = a%b; t = a; a = b; b = t; }return a; }
inline ll lcm(ll a, ll b){ return a / gcd(a, b)*b; }
inline ll gcd(ll a, ll b, ll c){ return gcd(gcd(a, b), c); }
inline int gcd(int a, int b, int c){ return gcd(gcd(a, b), c); }

// Useful constants

#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define mod         1000000007
#define PI          3.14159265358979323
#define link        asaxlajrewqwe
#define rank        wahayawehasdakw
//*************************************************************************************

const int BUSFIZE = 4096;
int read_int() {
    static char inbuf[BUSFIZE + 16];
    static char* inp = inbuf;
    static char* linp = inbuf + BUSFIZE;
    if (*inp == 0) {
        cin.read(inbuf, BUSFIZE);
        inp = inbuf;
    }
    while (*inp && (*inp < '0' || *inp > '9'))
        ++inp;
    int res = 0;
    while (*inp >= '0' && *inp <= '9') {
        res = res * 10 + *inp - '0';
        ++inp;
        if (inp == linp) {
            cin.read(inbuf, BUSFIZE);
            inp = inbuf;
        }
    }
    ++inp;
    return res;
}
static char outbuf[BUSFIZE + 16];
static char *outptr = outbuf;
static char *loutp = outbuf + BUSFIZE;
void write_int(int x) {
    char* begp = outptr;
    while (x) {
        int t = x / 10;
        char c = x - 10 * t + '0';
        *outptr++ = c;
        x = t;
    }
    char* endp = outptr - 1;
    while (begp < endp) {
        swap(*begp, *endp);
        ++begp;
        --endp;
    }
    if (outptr > loutp) {
        cout.write(outbuf, outptr - outbuf);
        outptr = outbuf;
    }
    *outptr++ = ' ';
}

int x[1008][1008];
void swap(char *a, char *b, int n) {
    int t = n % 64;
    if (t) {
        char buffer[64];
        memcpy(buffer, a, t);
        memcpy(a, b, t);
        memcpy(b, buffer, t);
        a += t;
        b += t;
    }
    n /= 64;
    typedef __m128i* Ptr;
    Ptr ptra = (Ptr)a;
    Ptr ptrb = (Ptr)b;
    while (n--) {
        __m128i t0 = _mm_loadu_si128(ptra + 0);
        __m128i t1 = _mm_loadu_si128(ptra + 1);
        __m128i t2 = _mm_loadu_si128(ptra + 2);
        __m128i t3 = _mm_loadu_si128(ptra + 3);
        __m128i t4 = _mm_loadu_si128(ptrb + 0);
        __m128i t5 = _mm_loadu_si128(ptrb + 1);
        __m128i t6 = _mm_loadu_si128(ptrb + 2);
        __m128i t7 = _mm_loadu_si128(ptrb + 3);
        _mm_storeu_si128(ptra + 0, t4);
        _mm_storeu_si128(ptra + 1, t5);
        _mm_storeu_si128(ptra + 2, t6);
        _mm_storeu_si128(ptra + 3, t7);
        _mm_storeu_si128(ptrb + 0, t0);
        _mm_storeu_si128(ptrb + 1, t1);
        _mm_storeu_si128(ptrb + 2, t2);
        _mm_storeu_si128(ptrb + 3, t3);
        ptra += 4;
        ptrb += 4;
    }
}
int v[1008 * 1008];
char data[1008][3008];
int vs = 0;

int main() {
#ifdef LOCAL
    FREIN("in.txt");
    FREOUT("out.txt");
#endif
    ios_base::sync_with_stdio(0);
    int n, m, q;
    n = read_int();
    m = read_int();
    q = read_int();
    FI(n) FJ(m) {
        v[vs] = read_int();
        int val = vs++;
        char *ptr = data[i] + j * 3;
        const char* valPtr = (const char*)&val;
        ptr[0] = valPtr[0];
        ptr[1] = valPtr[1];
        ptr[2] = valPtr[2];
    }
    while (q--) {
        int a, b, c, d, w, h;
        a = read_int();
        b = read_int();
        c = read_int();
        d = read_int();
        h = read_int();
        w = read_int();
        --a; --b; --c; --d;
        for (int i = 0; i < h; ++i) {
            swap(data[a + i] + b * 3, data[c + i] + d * 3, w * 3);
        }
    }
    FI(n) {
        FJ(m) {
            int val = 0;
            const char *ptr = data[i] + j * 3;
            char* valPtr = (char*)&val;
            valPtr[0] = ptr[0];
            valPtr[1] = ptr[1];
            valPtr[2] = ptr[2];
            val = v[val];
            write_int(val);
        }
        *outptr++ = '\n';
    }
    cout.write(outbuf, outptr - outbuf);
    CURTIME();
    return 0;
}


#pragma comment(linker, "/stack:20000000")
#define _CRT_SECURE_NO_WARNINGS
# include <iostream>
# include <cmath>
# include <algorithm>
# include <cstdio>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>

using namespace std;

// Let's define unordered map
# ifdef __GNUC__
# if __cplusplus > 199711L
# include <unordered_set>
# include <unordered_map>
# else
# include <tr1/unordered_map>
# include <tr1/unordered_set>
using namespace std::tr1;
# endif
# else
# include <unordered_map>
# include <unordered_set>
# endif

#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__, 5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,N,...) N
#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro, nargs) macro ## nargs
#define DBN1(a)         std::cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)       std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)     std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)   std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e) std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN(...) macro_dispatcher(DBN, __VA_ARGS__)(__VA_ARGS__)
#define DA(a,n) cout<<#a<<"=["; printarray(a,n); cout<<"]\n"
#define DAR(a,n,s) cout<<#a<<"["<<s<<"-"<<n-1<<"]=["; printarray(a,n,s); cout<<"]\n"

#ifdef _MSC_VER
#define ALIGN(x) __declspec(align(x))
#else
#define ALIGN(x) __attribute__((aligned(x)))
#endif

#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << std::endl
double __begin;
#define DTIME(ccc) __begin = clock(); ccc; std::cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<std::endl;

#define mp make_pair
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef int itn;

template<typename T1, typename T2, typename T3>
struct triple{ T1 a; T2 b; T3 c; triple() : a(T1()), b(T2()), c(T3()) {}; triple(T1 _a, T2 _b, T3 _c) :a(_a), b(_b), c(_c){} };
#define tri triple<int,int,int>
#define trll triple<ll,ll,ll>
template<typename T1, typename T2, typename T3>
bool operator<(const triple<T1, T2, T3> &t1, const triple<T1, T2, T3> &t2){ if (t1.a != t2.a) return t1.a<t2.a; else if (t1.b != t2.b) return t1.b<t2.b; else return t1.c < t2.c; }

#define FI(n) for(int i=0;i<n;++i)
#define FJ(n) for(int j=0;j<n;++j)
#define FK(n) for(int k=0;k<n;++k)
#define all(a) a.begin(), a.end()
//int some_primes[10] = {100271, 500179, 1000003, 2000227, 5000321}

inline int bits_count(int v){ v = v - ((v >> 1) & 0x55555555); v = (v & 0x33333333) + ((v >> 2) & 0x33333333); return((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; }
inline int bits_count(ll v){ int t = v >> 32; int p = (v & ((1LL << 32) - 1)); return bits_count(t) + bits_count(p); }
unsigned int reverse_bits(register unsigned int x){ x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1)); x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2)); x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4)); x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8)); return((x >> 16) | (x << 16)); }
inline int sign(int x){ return x > 0; }
inline bool isPowerOfTwo(int x){ return (x != 0 && (x&(x - 1)) == 0); }
#define checkbit(n, b) ((n >> b) & 1)
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())

//STL output ********************************
template<typename T1, typename T2> inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p);
template<typename T> inline std::ostream &operator<<(std::ostream &os, const std::vector<T>& v);
template<typename T>inline std::ostream &operator<<(std::ostream &os, const std::set<T>&v);
template<typename T1, typename T2>inline std::ostream &operator << (std::ostream & os, const std::map<T1, T2>& v);
template<typename T1, typename T2, typename T3> inline std::ostream& operator << (std::ostream& os, const triple<T1, T2, T3>& t);
template<typename T1, typename T2> inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p){ return os << "(" << p.first << ", " << p.second << ")"; }
template<typename T>inline std::ostream &operator<<(std::ostream &os, const std::vector<T>& v){ bool first = true; os << "["; for (unsigned int i = 0; i<v.size(); i++){ if (!first)os << ", "; os << v[i]; first = false; }return os << "]"; }
template<typename T>inline std::ostream &operator<<(std::ostream &os, const std::set<T>&v){ bool first = true; os << "["; for (auto ii = v.begin(); ii != v.end(); ++ii){ if (!first)os << ", "; os << *ii; first = false; }return os << "]"; }
template<typename T1, typename T2>inline std::ostream &operator << (std::ostream & os, const std::map<T1, T2>& v){ bool first = true; os << "["; for (auto ii = v.begin(); ii != v.end(); ++ii){ if (!first)os << ", "; os << *ii; first = false; }return os << "]"; }
template<typename T, typename T2>void printarray(T  a[], T2 sz, T2 beg = 0){ for (T2 i = beg; i<sz; i++) cout << a[i] << " "; cout << endl; }
template<typename T1, typename T2, typename T3>
inline std::ostream& operator << (std::ostream& os, const triple<T1, T2, T3>& t){ return os << "(" << t.a << ", " << t.b << ", " << t.c << ")"; }

//Pair magic
template<typename T1, typename T2> inline pair<T1, T2> operator+(const pair<T1, T2> &p1 , const pair<T1, T2> &p2) { return pair<T1, T2>(p1.first + p2.first, p1.second + p2.second); }
template<typename T1, typename T2> inline pair<T1, T2> operator-(const pair<T1, T2> &p1 , const pair<T1, T2> &p2) { return pair<T1, T2>(p1.first - p2.first, p1.second - p2.second); }

#define FREIN(FILE) freopen(FILE, "rt", stdin)
#define FREOUT(FILE) freopen(FILE, "wt", stdout)

#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(1.0 * (x))
#define pow(x, n) pow(1.0 * (x), n)

inline ll mulmod(ll x, ll n, ll _mod){ ll res = 0; while (n){ if (n & 1)res = (res + x) % _mod; x = (x + x) % _mod; n >>= 1; }return res; }
inline ll powmod(ll x, ll n, ll _mod){ ll res = 1; while (n){ if (n & 1)res = (res*x) % _mod; x = (x*x) % _mod; n >>= 1; }return res; }
inline ll gcd(ll a, ll b){ ll t; while (b){ a = a%b; t = a; a = b; b = t; }return a; }
inline int gcd(int a, int b){ int t; while (b){ a = a%b; t = a; a = b; b = t; }return a; }
inline ll lcm(ll a, ll b){ return a / gcd(a, b)*b; }
inline ll gcd(ll a, ll b, ll c){ return gcd(gcd(a, b), c); }
inline int gcd(int a, int b, int c){ return gcd(gcd(a, b), c); }

// Useful constants

#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define mod         1000000007
#define PI          3.14159265358979323
#define link        asaxlajrewqwe
#define rank        wahayawehasdakw
//*************************************************************************************

const int BUSFIZE = 4096;
int read_int() {
    static char inbuf[BUSFIZE + 16];
    static char* inp = inbuf;
    static char* linp = inbuf + BUSFIZE;
    if (*inp == 0) {
        cin.read(inbuf, BUSFIZE);
        inp = inbuf;
    }
    while (*inp && (*inp < '0' || *inp > '9'))
        ++inp;
    int res = 0;
    while (*inp >= '0' && *inp <= '9') {
        res = res * 10 + *inp - '0';
        ++inp;
        if (inp == linp) {
            cin.read(inbuf, BUSFIZE);
            inp = inbuf;
        }
    }
    ++inp;
    return res;
}
static char outbuf[BUSFIZE + 16];
static char *outptr = outbuf;
static char *loutp = outbuf + BUSFIZE;
void write_int(int x) {
    char* begp = outptr;
    while (x) {
        int t = x / 10;
        char c = x - 10 * t + '0';
        *outptr++ = c;
        x = t;
    }
    char* endp = outptr - 1;
    while (begp < endp) {
        swap(*begp, *endp);
        ++begp;
        --endp;
    }
    if (outptr > loutp) {
        cout.write(outbuf, outptr - outbuf);
        outptr = outbuf;
    }
    *outptr++ = ' ';
}

int x[1008][1008];
void swap(char *a, char *b, int n) {
    char buffer[3008];
    int t = n % 16;
    if (t) {
        memcpy(buffer, a, t);
        memcpy(a, b, t);
        memcpy(b, buffer, t);
        a += t;
        b += t;
    }
    n /= 16;
    using Ptr = __m128i*;
    Ptr ptra = (Ptr)a;
    Ptr ptrb = (Ptr)b;
    int o = n % 4;
    while (o--) {
        __m128i t = _mm_loadu_si128(ptra);
        _mm_storeu_si128(ptra, _mm_loadu_si128(ptrb));
        _mm_storeu_si128(ptrb, t);
        ++ptra;
        ++ptrb;
    }
    int n4 = n / 4;
    while (n4--) {
        __m128i t0 = _mm_loadu_si128(ptra + 0);
        __m128i t1 = _mm_loadu_si128(ptra + 1);
        __m128i t2 = _mm_loadu_si128(ptra + 2);
        __m128i t3 = _mm_loadu_si128(ptra + 3);
        _mm_storeu_si128(ptra + 0, _mm_loadu_si128(ptrb + 0));
        _mm_storeu_si128(ptra + 1, _mm_loadu_si128(ptrb + 1));
        _mm_storeu_si128(ptra + 2, _mm_loadu_si128(ptrb + 2));
        _mm_storeu_si128(ptra + 3, _mm_loadu_si128(ptrb + 3));
        _mm_storeu_si128(ptrb + 0, t0);
        _mm_storeu_si128(ptrb + 1, t1);
        _mm_storeu_si128(ptrb + 2, t2);
        _mm_storeu_si128(ptrb + 3, t3);
        ptra += 4;
        ptrb += 4;
    }
}
int v[1008 * 1008];
char data[1008][3008];
int vs = 0;

int main() {
#ifdef LOCAL
    FREIN("in.txt");
    FREOUT("out.txt");
#endif
    ios_base::sync_with_stdio(0);
    int n, m, q;
    n = read_int();
    m = read_int();
    q = read_int();
    FI(n) FJ(m) {
        v[vs] = read_int();
        int val = vs++;
        char *ptr = data[i] + j * 3;
        const char* valPtr = (const char*)&val;
        ptr[0] = valPtr[0];
        ptr[1] = valPtr[1];
        ptr[2] = valPtr[2];
    }
    while (q--) {
        int a, b, c, d, w, h;
        a = read_int();
        b = read_int();
        c = read_int();
        d = read_int();
        h = read_int();
        w = read_int();
        --a; --b; --c; --d;
        for (int i = 0; i < h; ++i) {
            swap(data[a + i] + b * 3, data[c + i] + d * 3, w * 3);
        }
    }
    FI(n) {
        FJ(m) {
            int val = 0;
            const char *ptr = data[i] + j * 3;
            char* valPtr = (char*)&val;
            valPtr[0] = ptr[0];
            valPtr[1] = ptr[1];
            valPtr[2] = ptr[2];
            val = v[val];
            write_int(val);
        }
        *outptr++ = '\n';
    }
    cout.write(outbuf, outptr - outbuf);
    CURTIME();
    return 0;
}


#pragma comment(linker, "/stack:20000000")
#define _CRT_SECURE_NO_WARNINGS
# include <iostream>
# include <cmath>
# include <algorithm>
# include <cstdio>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>

using namespace std;

// Let's define unordered map
# ifdef __GNUC__
# if __cplusplus > 199711L
# include <unordered_set>
# include <unordered_map>
# else
# include <tr1/unordered_map>
# include <tr1/unordered_set>
using namespace std::tr1;
# endif
# else
# include <unordered_map>
# include <unordered_set>
# endif

#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__, 5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,N,...) N
#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro, nargs) macro ## nargs
#define DBN1(a)         std::cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)       std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)     std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)   std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e) std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN(...) macro_dispatcher(DBN, __VA_ARGS__)(__VA_ARGS__)
#define DA(a,n) cout<<#a<<"=["; printarray(a,n); cout<<"]\n"
#define DAR(a,n,s) cout<<#a<<"["<<s<<"-"<<n-1<<"]=["; printarray(a,n,s); cout<<"]\n"

#ifdef _MSC_VER
#define ALIGN(x) __declspec(align(x))
#else
#define ALIGN(x) __attribute__((aligned(x)))
#endif

#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << std::endl
double __begin;
#define DTIME(ccc) __begin = clock(); ccc; std::cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<std::endl;

#define mp make_pair
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef int itn;

template<typename T1, typename T2, typename T3>
struct triple{ T1 a; T2 b; T3 c; triple() : a(T1()), b(T2()), c(T3()) {}; triple(T1 _a, T2 _b, T3 _c) :a(_a), b(_b), c(_c){} };
#define tri triple<int,int,int>
#define trll triple<ll,ll,ll>
template<typename T1, typename T2, typename T3>
bool operator<(const triple<T1, T2, T3> &t1, const triple<T1, T2, T3> &t2){ if (t1.a != t2.a) return t1.a<t2.a; else if (t1.b != t2.b) return t1.b<t2.b; else return t1.c < t2.c; }

#define FI(n) for(int i=0;i<n;++i)
#define FJ(n) for(int j=0;j<n;++j)
#define FK(n) for(int k=0;k<n;++k)
#define all(a) a.begin(), a.end()
//int some_primes[10] = {100271, 500179, 1000003, 2000227, 5000321}

inline int bits_count(int v){ v = v - ((v >> 1) & 0x55555555); v = (v & 0x33333333) + ((v >> 2) & 0x33333333); return((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; }
inline int bits_count(ll v){ int t = v >> 32; int p = (v & ((1LL << 32) - 1)); return bits_count(t) + bits_count(p); }
unsigned int reverse_bits(register unsigned int x){ x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1)); x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2)); x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4)); x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8)); return((x >> 16) | (x << 16)); }
inline int sign(int x){ return x > 0; }
inline bool isPowerOfTwo(int x){ return (x != 0 && (x&(x - 1)) == 0); }
#define checkbit(n, b) ((n >> b) & 1)
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())

//STL output ********************************
template<typename T1, typename T2> inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p);
template<typename T> inline std::ostream &operator<<(std::ostream &os, const std::vector<T>& v);
template<typename T>inline std::ostream &operator<<(std::ostream &os, const std::set<T>&v);
template<typename T1, typename T2>inline std::ostream &operator << (std::ostream & os, const std::map<T1, T2>& v);
template<typename T1, typename T2, typename T3> inline std::ostream& operator << (std::ostream& os, const triple<T1, T2, T3>& t);
template<typename T1, typename T2> inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p){ return os << "(" << p.first << ", " << p.second << ")"; }
template<typename T>inline std::ostream &operator<<(std::ostream &os, const std::vector<T>& v){ bool first = true; os << "["; for (unsigned int i = 0; i<v.size(); i++){ if (!first)os << ", "; os << v[i]; first = false; }return os << "]"; }
template<typename T>inline std::ostream &operator<<(std::ostream &os, const std::set<T>&v){ bool first = true; os << "["; for (auto ii = v.begin(); ii != v.end(); ++ii){ if (!first)os << ", "; os << *ii; first = false; }return os << "]"; }
template<typename T1, typename T2>inline std::ostream &operator << (std::ostream & os, const std::map<T1, T2>& v){ bool first = true; os << "["; for (auto ii = v.begin(); ii != v.end(); ++ii){ if (!first)os << ", "; os << *ii; first = false; }return os << "]"; }
template<typename T, typename T2>void printarray(T  a[], T2 sz, T2 beg = 0){ for (T2 i = beg; i<sz; i++) cout << a[i] << " "; cout << endl; }
template<typename T1, typename T2, typename T3>
inline std::ostream& operator << (std::ostream& os, const triple<T1, T2, T3>& t){ return os << "(" << t.a << ", " << t.b << ", " << t.c << ")"; }

//Pair magic
template<typename T1, typename T2> inline pair<T1, T2> operator+(const pair<T1, T2> &p1 , const pair<T1, T2> &p2) { return pair<T1, T2>(p1.first + p2.first, p1.second + p2.second); }
template<typename T1, typename T2> inline pair<T1, T2> operator-(const pair<T1, T2> &p1 , const pair<T1, T2> &p2) { return pair<T1, T2>(p1.first - p2.first, p1.second - p2.second); }

#define FREIN(FILE) freopen(FILE, "rt", stdin)
#define FREOUT(FILE) freopen(FILE, "wt", stdout)

#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(1.0 * (x))
#define pow(x, n) pow(1.0 * (x), n)

inline ll mulmod(ll x, ll n, ll _mod){ ll res = 0; while (n){ if (n & 1)res = (res + x) % _mod; x = (x + x) % _mod; n >>= 1; }return res; }
inline ll powmod(ll x, ll n, ll _mod){ ll res = 1; while (n){ if (n & 1)res = (res*x) % _mod; x = (x*x) % _mod; n >>= 1; }return res; }
inline ll gcd(ll a, ll b){ ll t; while (b){ a = a%b; t = a; a = b; b = t; }return a; }
inline int gcd(int a, int b){ int t; while (b){ a = a%b; t = a; a = b; b = t; }return a; }
inline ll lcm(ll a, ll b){ return a / gcd(a, b)*b; }
inline ll gcd(ll a, ll b, ll c){ return gcd(gcd(a, b), c); }
inline int gcd(int a, int b, int c){ return gcd(gcd(a, b), c); }

// Useful constants

#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define mod         1000000007
#define PI          3.14159265358979323
#define link        asaxlajrewqwe
#define rank        wahayawehasdakw
//*************************************************************************************

const int BUSFIZE = 4096;
int read_int() {
    static char inbuf[BUSFIZE + 16];
    static char* inp = inbuf;
    static char* linp = inbuf + BUSFIZE;
    if (*inp == 0) {
        cin.read(inbuf, BUSFIZE);
        inp = inbuf;
    }
    while (*inp && (*inp < '0' || *inp > '9'))
        ++inp;
    int res = 0;
    while (*inp >= '0' && *inp <= '9') {
        res = res * 10 + *inp - '0';
        ++inp;
        if (inp == linp) {
            cin.read(inbuf, BUSFIZE);
            inp = inbuf;
        }
    }
    ++inp;
    return res;
}
static char outbuf[BUSFIZE + 16];
static char *outptr = outbuf;
static char *loutp = outbuf + BUSFIZE;
void write_int(int x) {
    char* begp = outptr;
    while (x) {
        int t = x / 10;
        char c = x - 10 * t + '0';
        *outptr++ = c;
        x = t;
    }
    char* endp = outptr - 1;
    while (begp < endp) {
        swap(*begp, *endp);
        ++begp;
        --endp;
    }
    if (outptr > loutp) {
        cout.write(outbuf, outptr - outbuf);
        outptr = outbuf;
    }
    *outptr++ = ' ';
}

int x[1008][1008];
void swap(char *a, char *b, int n) {
    char buffer[3008];
    ssse3_memcpy(buffer, a, n);
    ssse3_memcpy(a, b, n);
    ssse3_memcpy(b, buffer, n);
}
int v[1008 * 1008];
char data[1008][3008];
int vs = 0;

int main() {
//    FREIN("in.txt");
//    FREOUT("out.txt");
    ios_base::sync_with_stdio(0);
    int n, m, q;
    n = read_int();
    m = read_int();
    q = read_int();
    FI(n) FJ(m) {
        v[vs] = read_int();
        int val = vs++;
        char *ptr = data[i] + j * 3;
        const char* valPtr = (const char*)&val;
        ptr[0] = valPtr[0];
        ptr[1] = valPtr[1];
        ptr[2] = valPtr[2];
    }
    while (q--) {
        int a, b, c, d, w, h;
        a = read_int();
        b = read_int();
        c = read_int();
        d = read_int();
        h = read_int();
        w = read_int();
        --a; --b; --c; --d;
        for (int i = 0; i < h; ++i) {
            swap(data[a + i] + b * 3, data[c + i] + d * 3, w * 3);
        }
    }
    FI(n) {
        FJ(m) {
            int val = 0;
            const char *ptr = data[i] + j * 3;
            char* valPtr = (char*)&val;
            valPtr[0] = ptr[0];
            valPtr[1] = ptr[1];
            valPtr[2] = ptr[2];
            val = v[val];
            write_int(val);
        }
        *outptr++ = '\n';
    }
    cout.write(outbuf, outptr - outbuf);
    CURTIME();
    return 0;
}


#include <stdio.h>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;
#define ll long long
struct Node {
	int val;
	Node* below, *right;
	Node() { below = right = NULL; }
};
Node f[1001][1001];
void sw(Node* a, Node* b, int e) {
	if (e == 0) { // right change
		Node* t = a->right;
		a->right = b->right;
		b->right = t;
	}
	else {
		Node* t = a->below;
		a->below = b->below;
		b->below = t;
	}
}
int main(){
	int n, m, q;
	scanf("%d %d %d", &n, &m, &q);
	for (int i = 1; i <= n; i++)
		f[i - 1][0].below = &f[i][0];
	for (int j = 1; j <= m; j++)
		f[0][j-1].right = &f[0][j];
	for (int i = 1; i <= n; i++)for (int j = 1; j <= m; j++) {
		f[i - 1][j].below = f[i][j - 1].right = &f[i][j];
		scanf("%d", &f[i][j].val);
	}
	while (q--) {
		int a, b, x, y, h, w;
		scanf("%d %d %d %d %d %d", &a, &b, &x, &y, &h, &w);
		Node* aroot, *xroot, *aa, *xx;
		aroot = xroot = &f[0][0];
		for (int i = 1; i < a; i++)aroot = aroot->below;
		for (int i = 1; i < b; i++)aroot = aroot->right;
		for (int i = 1; i < x; i++)xroot = xroot->below;
		for (int i = 1; i < y; i++)xroot = xroot->right;
		aa = aroot, xx = xroot;
		for (int i = 0; i < h; i++) {
			aa = aa->below, xx = xx->below;
			sw(aa, xx, 0);	// right swap
		}
		aa = aroot, xx = xroot;
		for (int i = 0; i < w; i++) {
			aa = aa->right, xx = xx->right;
			sw(aa, xx, 1);
		}
		aa = aroot, xx = xroot;
		for (int i = 0; i < h; i++)
			aa = aa->below, xx = xx->below;
		for (int i = 0; i < w; i++) {
			aa = aa->right, xx = xx->right;
			sw(aa, xx, 1);
		}

		aa = aroot, xx = xroot;
		for (int i = 0; i < w; i++)
			aa = aa->right, xx = xx->right;
		for (int i = 0; i < h; i++) {
			aa = aa->below, xx = xx->below;
			sw(aa, xx, 0);
		}
	}
	Node* root = f[0][0].below;
	for (int i = 0; i < n; i++) {
		Node* p = root;
		for (int cnt = 0; cnt < m; cnt++) {
			p = p->right;
			printf("%d ", p->val);
		}
		printf("\n");
		if(root->below != NULL) root = root->below;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

using namespace std;

namespace __lightspeed_thingy {
  int read() {
    int x = 0;
    char c;
    do {
      c = getchar();
    } while (c <= 32);
    while ('0' <= c && c <= '9') {
      x = 10 * x + c - '0';
      c = getchar();
    }
    return x;
  }

  void _int_to_char(int *a, char *b, unsigned int n, unsigned short bts = 4) {
    for (unsigned int i = 0; i < n; i++) {
      const char* ac = (const char*)&a[i];
      for (unsigned int j = 0; j < bts; j++) {
        b[j] = ac[j];
      }
      b += bts;
    }
  }

  void _char_to_int(char *b, int *a, unsigned int n, unsigned short bts = 4) {
    for (unsigned int i = 0; i < n; i++) {
      int x = 0;
      char *xc = (char*)&x;
      for (unsigned int j = 0; j < bts; j++) {
        xc[j] = b[j];
      }
      a[i] = x;
      b += bts;
    }
  }

  void _memcpy(char *a, char *b, unsigned int n) {
    const unsigned short remainder = n % 64;
    if (remainder) {
      memcpy(a, b, remainder);
      a += remainder;
      b += remainder;
    }
    n /= 64;
    __m128i* ptr_a = (__m128i*)a;
    __m128i* ptr_b = (__m128i*)b;
    while (n--) {
      _mm_storeu_si128(ptr_a, _mm_loadu_si128(ptr_b));
      _mm_storeu_si128(ptr_a + 1, _mm_loadu_si128(ptr_b + 1));
      _mm_storeu_si128(ptr_a + 2, _mm_loadu_si128(ptr_b + 2));
      _mm_storeu_si128(ptr_a + 3, _mm_loadu_si128(ptr_b + 3));
      ptr_a += 4;
      ptr_b += 4;
    }
  }

  void _memswap(char *a, char *b, unsigned int n) {
    const unsigned short remainder = n % 64;
    if (remainder) {
      char buffer[64];
      memcpy(buffer, a, remainder);
      memcpy(a, b, remainder);
      memcpy(b, buffer, remainder);
      a += remainder;
      b += remainder;
    }
    n /= 64;
    __m128i* ptr_a = (__m128i*)a;
    __m128i* ptr_b = (__m128i*)b;
    while (n--) {
      register __m128i t0 = _mm_loadu_si128(ptr_a);
      register __m128i t1 = _mm_loadu_si128(ptr_a + 1);
      register __m128i t2 = _mm_loadu_si128(ptr_a + 2);
      register __m128i t3 = _mm_loadu_si128(ptr_a + 3);
      register __m128i t4 = _mm_loadu_si128(ptr_b);
      _mm_storeu_si128(ptr_b, t0);
      t0 = _mm_loadu_si128(ptr_b + 1);
      _mm_storeu_si128(ptr_b + 1, t1);
      t1 = _mm_loadu_si128(ptr_b + 2);
      _mm_storeu_si128(ptr_b + 2, t2);
      t2 = _mm_loadu_si128(ptr_b + 3);
      _mm_storeu_si128(ptr_b + 3, t3);
      _mm_storeu_si128(ptr_a, t4);
      _mm_storeu_si128(ptr_a + 1, t0);
      _mm_storeu_si128(ptr_a + 2, t1);
      _mm_storeu_si128(ptr_a + 3, t2);
      ptr_a += 4;
      ptr_b += 4;
    }
  }

  void _memadd(char *a, char *b, unsigned int n) {
    const unsigned short remainder = n % 64;
    if (remainder) {
      for (unsigned int i = 0; i < remainder; i++) {
        a[i] += b[i];
      }
      a += remainder;
      b += remainder;
    }
    n /= 64;
    __m128i* ptr_a = (__m128i*)a;
    __m128i* ptr_b = (__m128i*)b;
    while (n--) {
      register __m128i t0 = _mm_loadu_si128(ptr_a);
      register __m128i t1 = _mm_loadu_si128(ptr_a + 1);
      register __m128i t2 = _mm_loadu_si128(ptr_a + 2);
      register __m128i t3 = _mm_loadu_si128(ptr_a + 3);
      register __m128i t4 = _mm_loadu_si128(ptr_b);
      register __m128i t5 = _mm_loadu_si128(ptr_b + 1);
      register __m128i t6 = _mm_loadu_si128(ptr_b + 2);
      register __m128i t7 = _mm_loadu_si128(ptr_b + 3);
      _mm_storeu_si128(ptr_a, _mm_add_epi32(t0, t4));
      _mm_storeu_si128(ptr_a + 1, _mm_add_epi32(t1, t5));
      _mm_storeu_si128(ptr_a + 2, _mm_add_epi32(t2, t6));
      _mm_storeu_si128(ptr_a + 3, _mm_add_epi32(t3, t7));
      ptr_a += 4;
      ptr_b += 4;
    }
  }

  void _memsub(char *a, char *b, unsigned int n) {
    const unsigned short remainder = n % 64;
    if (remainder) {
      for (unsigned int i = 0; i < remainder; i++) {
        a[i] -= b[i];
      }
      a += remainder;
      b += remainder;
    }
    n /= 64;
    __m128i* ptr_a = (__m128i*)a;
    __m128i* ptr_b = (__m128i*)b;
    while (n--) {
      register __m128i t0 = _mm_loadu_si128(ptr_a);
      register __m128i t1 = _mm_loadu_si128(ptr_a + 1);
      register __m128i t2 = _mm_loadu_si128(ptr_a + 2);
      register __m128i t3 = _mm_loadu_si128(ptr_a + 3);
      register __m128i t4 = _mm_loadu_si128(ptr_b);
      register __m128i t5 = _mm_loadu_si128(ptr_b + 1);
      register __m128i t6 = _mm_loadu_si128(ptr_b + 2);
      register __m128i t7 = _mm_loadu_si128(ptr_b + 3);
      _mm_storeu_si128(ptr_a, _mm_add_epi32(t0, t4));
      _mm_storeu_si128(ptr_a + 1, _mm_sub_epi32(t1, t5));
      _mm_storeu_si128(ptr_a + 2, _mm_sub_epi32(t2, t6));
      _mm_storeu_si128(ptr_a + 3, _mm_sub_epi32(t3, t7));
      ptr_a += 4;
      ptr_b += 4;
    }
  }

  int intersection_size(const vector<int> &a, const vector<int> &b){
    const int *ap = a.data(), *bp = b.data();
    const int a_len = a.size(), b_len = b.size();
    int ai = 0, bi = 0, answer = 0;
    const int st_a = a_len & ~3, st_b = b_len & ~3;
    while (ai < st_a && bi < st_b) {
      __m128i v_a = _mm_loadu_si128((__m128i*)&ap[ai]);
      __m128i v_b = _mm_loadu_si128((__m128i*)&bp[bi]);
      const int a_max = _mm_extract_epi32(v_a, 3);
      const int b_max = _mm_extract_epi32(v_b, 3);
      ai += (a_max <= b_max) * 4;
      bi += (a_max >= b_max) * 4;
      const __m128i cmp_mask1 = _mm_cmpeq_epi32(v_a, v_b);
      v_b = _mm_shuffle_epi32(v_b, _MM_SHUFFLE(0, 3, 2, 1));
      const __m128i cmp_mask2 = _mm_cmpeq_epi32(v_a, v_b);
      v_b = _mm_shuffle_epi32(v_b, _MM_SHUFFLE(0, 3, 2, 1));
      const __m128i cmp_mask3 = _mm_cmpeq_epi32(v_a, v_b);
      v_b = _mm_shuffle_epi32(v_b, _MM_SHUFFLE(0, 3, 2, 1));
      const __m128i cmp_mask4 = _mm_cmpeq_epi32(v_a, v_b);
      const __m128i cmp_mask = _mm_or_si128(
      _mm_or_si128(cmp_mask1, cmp_mask2),
      _mm_or_si128(cmp_mask3, cmp_mask4));
      const int mask = _mm_movemask_ps(_mm_castsi128_ps(cmp_mask));
      answer += _mm_popcnt_u32(mask);
    }
    while (ai < a_len && bi < b_len) {
      const int x = ap[ai], y = bp[bi];
      ai += (x <= y);
      bi += (x >= y);
      answer += (x == y);
    }
    return answer;
  }
};

char data[1005][3005];
unsigned int restore[1000005];

int main() {
  const unsigned int n = __lightspeed_thingy::read();
  const unsigned int m = __lightspeed_thingy::read();
  unsigned int q = __lightspeed_thingy::read();
  unsigned int temp_id = 0;
  int a[1005];
  for (unsigned int i = 0; i < n; i++) {
    for (unsigned int j = 0; j < m; j++) {
      const unsigned int x = __lightspeed_thingy::read();
      restore[temp_id] = x;
      a[j] = temp_id++;
    }
    __lightspeed_thingy::_int_to_char(a, data[i], m, 3);
  }
  while (q--) {
    const unsigned int a = __lightspeed_thingy::read() - 1;
    const unsigned int b = 3 * __lightspeed_thingy::read() - 3;
    const unsigned int c = __lightspeed_thingy::read() - 1;
    const unsigned int d = 3 * __lightspeed_thingy::read() - 3;
    const unsigned int h = __lightspeed_thingy::read();
    const unsigned int w = 3 * __lightspeed_thingy::read();
    for (unsigned int i = 0; i < h; i++) {
      __lightspeed_thingy::_memswap(data[a + i] + b, data[c + i] + d, w);
    }
  }
  for (unsigned int i = 0; i < n; i++) {
    __lightspeed_thingy::_char_to_int(data[i], a, m, 3);
    for (unsigned int j = 0; j < m; j++) {
      printf("%d ", restore[a[j]]);
    }
    printf("\n");
  }
  return 0;
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
struct leave
{
	int value;
	int right;
	int lower;
};
leave build()
{
	leave l;
	l.value = -1;
	l.right = -1;
	l.lower = -1;
	return l;
};

int r(const vector<leave> &a, int n, int l)
{
	leave point = a[n];
	int num = n;
	for (int i = 0; i < l; ++i)
	{
		num = point.right;
		point = a[point.right];
	}
	return num;
}
int d(const vector<leave> &a, int n, int l)
{
	leave point = a[n];
	int num = n;
	for (int i = 0; i < l; ++i)
	{
		num = point.lower;
		point = a[point.lower];
	}
	return num;
}
int go_to(const vector<leave> &a, int x, int y)
{
	int temp = r(a, 0, x);
	return d(a, temp, y);
}

void change(vector<leave> &a, int x1, int y1, int x2, int y2, int w, int h)
{
	int i11 = go_to(a, x1 - 1, y1 - 1),     i12 = go_to(a, x2 - 1, y2 - 1);
	int i21 = go_to(a, x1 - 1, y1 - 1),     i22 = go_to(a, x2 - 1, y2 - 1);
	int i31 = go_to(a, x1 - 1, y1 + h - 1), i32 = go_to(a, x2 - 1, y2 + h - 1);
	int i41 = go_to(a, x1 + w - 1, y1 - 1), i42 = go_to(a, x2 + w - 1, y2 - 1);

    //меняем нижних соседей верхней перекладины
	for (int i = 0; i < w; ++i)
	{
		i11 = r(a, i11, 1);
		i12 = r(a, i12, 1);
		int temp = a[i11].lower;
		a[i11].lower = a[i12].lower;
		a[i12].lower = temp;
	}
	//меняем правых соседей левой штанги
	for (int i = 0; i < h; ++i)
	{
		i21 = d(a, i21, 1);
		i22 = d(a, i22, 1);
		int temp = a[i21].right;
		a[i21].right = a[i22].right;
		a[i22].right = temp;
	}
	//меняем нижних соседей нижней перекладины
	for (int i = 0; i < w; ++i)
	{
		i31 = r(a, i31, 1);
		i32 = r(a, i32, 1);
		int temp = a[i31].lower;
		a[i31].lower = a[i32].lower;
		a[i32].lower = temp;
	}
	//меняем правых соседей правой штанги
	for (int i = 0; i < h; ++i)
	{
		i41 = d(a, i41, 1);
		i42 = d(a, i42, 1);
		int temp = a[i41].right;
		a[i41].right = a[i42].right;
		a[i42].right = temp;
	}
}
void print(const vector<leave>a, int n, int m)
{
	for (int i = 1; i <= n; ++i)
	{
		int t = go_to(a, 0, i);
		for (int j = 1; j <= m; ++j)
		{
			t = r(a, t, 1);
			cout << a[t].value << " ";
		}
		cout << endl;
	}
}
int main()
{
	int n, m, q, i, j;
	cin >> n >> m >> q;
	vector<int> x1(q), y1(q), x2(q), y2(q), w(q), h(q);
	vector< vector< int > > A(n + 2);
	for (i = 0; i < n + 2; ++i) A[i].resize(m + 2);

	for (i = 1; i <= n; ++i)
	{
		for (j = 1; j <= m; ++j)
		{
			cin >> A[i][j];
		}
	}
	//Ввод координат прямоугольников
	for (i = 0; i < q; ++i)
	{
		cin >> y1[i] >> x1[i] >> y2[i] >> x2[i] >> h[i] >> w[i];
	}
	for (i = 0; i < n + 2; ++i)
	{
		for (j = 0; j < m + 2; ++j)
		{
			if (i == 0 || j == 0 || i == n + 1 || j == m + 1) A[i][j] = -1;
		}
	}
	//Делаем из таблицы массив "a"
	vector <leave> a((m + 2)*(n + 2));
	for (i = 0; i < n + 2; ++i)
	{
		for (j = 0; j < m + 2; ++j)
		{
			a[(m + 2)*i + j].value = A[i][j];
		}
	}
	for (i = 0; i < n + 2; ++i)
	{
		for (j = 0; j < m + 2; ++j)
		{
			if (i != n + 1)
			{
				a[(m + 2)*i + j].lower = (m + 2)*i + j + m + 2;
			}
			else a[(m + 2)*i + j].lower = -1;
			if (j != m + 1)
			{
				a[(m + 2)*i + j].right = (m + 2)*i + j + 1;
			}
			else a[(m + 2)*i + j].right = -1;
		}
	}
	//Замена прямоугольников
	for (i = 0; i < q; ++i)
	{
		change(a, x1[i], y1[i], x2[i], y2[i], w[i], h[i]);
		//print(a, n, m);
	}
	//Финальный вывод
	print(a, n, m);
 	return 0;
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
struct leave
{
	int value;
	int right;
	int lower;
};
leave build()
{
	leave l;
	l.value = -1;
	l.right = -1;
	l.lower = -1;
	return l;
};

int r(vector<leave> a, int n, int l)
{
	leave point = a[n];
	int num = n;
	for (int i = 0; i < l; ++i)
	{
		num = point.right;
		point = a[point.right];
	}
	return num;
}
int d(vector<leave> a, int n, int l)
{
	leave point = a[n];
	int num = n;
	for (int i = 0; i < l; ++i)
	{
		num = point.lower;
		point = a[point.lower];
	}
	return num;
}
int go_to(vector<leave> a, int x, int y)
{
	int temp = r(a, 0, x);
	return d(a, temp, y);
}

void change(vector<leave> &a, int x1, int y1, int x2, int y2, int w, int h)
{
	int i11 = go_to(a, x1 - 1, y1 - 1),     i12 = go_to(a, x2 - 1, y2 - 1);
	int i21 = go_to(a, x1 - 1, y1 - 1),     i22 = go_to(a, x2 - 1, y2 - 1);
	int i31 = go_to(a, x1 - 1, y1 + h - 1), i32 = go_to(a, x2 - 1, y2 + h - 1);
	int i41 = go_to(a, x1 + w - 1, y1 - 1), i42 = go_to(a, x2 + w - 1, y2 - 1);

    //меняем нижних соседей верхней перекладины
	for (int i = 0; i < w; ++i)
	{
		i11 = r(a, i11, 1);
		i12 = r(a, i12, 1);
		int temp = a[i11].lower;
		a[i11].lower = a[i12].lower;
		a[i12].lower = temp;
	}
	//меняем правых соседей левой штанги
	for (int i = 0; i < h; ++i)
	{
		i21 = d(a, i21, 1);
		i22 = d(a, i22, 1);
		int temp = a[i21].right;
		a[i21].right = a[i22].right;
		a[i22].right = temp;
	}
	//меняем нижних соседей нижней перекладины
	for (int i = 0; i < w; ++i)
	{
		i31 = r(a, i31, 1);
		i32 = r(a, i32, 1);
		int temp = a[i31].lower;
		a[i31].lower = a[i32].lower;
		a[i32].lower = temp;
	}
	//меняем правых соседей правой штанги
	for (int i = 0; i < h; ++i)
	{
		i41 = d(a, i41, 1);
		i42 = d(a, i42, 1);
		int temp = a[i41].right;
		a[i41].right = a[i42].right;
		a[i42].right = temp;
	}
}
void print(vector<leave>a, int n, int m)
{
	for (int i = 1; i <= n; ++i)
	{
		int t = go_to(a, 0, i);
		for (int j = 1; j <= m; ++j)
		{
			t = r(a, t, 1);
			cout << a[t].value << " ";
		}
		cout << endl;
	}
}
int main()
{
	int n, m, q, i, j;
	cin >> n >> m >> q;
	vector<int> x1(q), y1(q), x2(q), y2(q), w(q), h(q);
	vector< vector< int > > A(n + 2);
	for (i = 0; i < n + 2; ++i) A[i].resize(m + 2);

	for (i = 1; i <= n; ++i)
	{
		for (j = 1; j <= m; ++j)
		{
			cin >> A[i][j];
		}
	}
	//Ввод координат прямоугольников
	for (i = 0; i < q; ++i)
	{
		cin >> y1[i] >> x1[i] >> y2[i] >> x2[i] >> h[i] >> w[i];
	}
	for (i = 0; i < n + 2; ++i)
	{
		for (j = 0; j < m + 2; ++j)
		{
			if (i == 0 || j == 0 || i == n + 1 || j == m + 1) A[i][j] = -1;
		}
	}
	//Делаем из таблицы массив "a"
	vector <leave> a((m + 2)*(n + 2));
	for (i = 0; i < n + 2; ++i)
	{
		for (j = 0; j < m + 2; ++j)
		{
			a[(m + 2)*i + j].value = A[i][j];
		}
	}
	for (i = 0; i < n + 2; ++i)
	{
		for (j = 0; j < m + 2; ++j)
		{
			if (i != n + 1)
			{
				a[(m + 2)*i + j].lower = (m + 2)*i + j + m + 2;
			}
			else a[(m + 2)*i + j].lower = -1;
			if (j != m + 1)
			{
				a[(m + 2)*i + j].right = (m + 2)*i + j + 1;
			}
			else a[(m + 2)*i + j].right = -1;
		}
	}
	//Замена прямоугольников
	for (i = 0; i < q; ++i)
	{
		change(a, x1[i], y1[i], x2[i], y2[i], w[i], h[i]);
		//print(a, n, m);
	}
	//Финальный вывод
	print(a, n, m);
 	return 0;
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
struct leave
{
	int value;
	int right;
	int lower;
};
leave build()
{
	leave l;
	l.value = -1;
	l.right = -1;
	l.lower = -1;
	return l;
};

int r(vector<leave> a, int n, int l)
{
	leave point = a[n];
	int num = n;
	for (int i = 0; i < l; ++i)
	{
		num = point.right;
		point = a[point.right];
	}
	return num;
}
int d(vector<leave> a, int n, int l)
{
	leave point = a[n];
	int num = n;
	for (int i = 0; i < l; ++i)
	{
		num = point.lower;
		point = a[point.lower];
	}
	return num;
}
int go_to(vector<leave> a, int x, int y)
{
	return d(a, r(a, 0, x), y);
}

void change(vector<leave> &a, int x1, int y1, int x2, int y2, int w, int h)
{
	int i11 = go_to(a, x1 - 1, y1 - 1), i12 = go_to(a, x2 - 1, y2 - 1);
	int i21 = go_to(a, x1 - 1, y1 - 1), i22 = go_to(a, x2 - 1, y2 - 1);
	int i31 = go_to(a, x1 - 1, y1 + h - 1), i32 = go_to(a, x2 - 1, y2 + h - 1);
	int i41 = go_to(a, x1 + w - 1, y1 - 1), i42 = go_to(a, x2 + w - 1, y2 - 1);
	//меняем нижних соседей верхней перекладины
	for (int i = 0; i < w; ++i)
	{
		i11 = r(a, i11, 1);
		i12 = r(a, i12, 1);
		int temp = a[i11].lower;
		a[i11].lower = a[i12].lower;
		a[i12].lower = temp;
	}
	//меняем правых соседей левой штанги
	for (int i = 0; i < h; ++i)
	{
		i21 = d(a, i21, 1);
		i22 = d(a, i22, 1);
		int temp = a[i21].right;
		a[i21].right = a[i22].right;
		a[i22].right = temp;
	}
	//меняем нижних соседей нижней перекладины
	for (int i = 0; i < w; ++i)
	{
		i31 = r(a, i31, 1);
		i32 = r(a, i32, 1);
		int temp = a[i31].lower;
		a[i31].lower = a[i32].lower;
		a[i32].lower = temp;
	}
	//меняем правых соседей правой штанги
	for (int i = 0; i < h; ++i)
	{
		i41 = d(a, i41, 1);
		i42 = d(a, i42, 1);
		int temp = a[i41].right;
		a[i41].right = a[i42].right;
		a[i42].right = temp;
	}
}
void print(vector<leave>a, int n, int m)
{
	for (int i = 1; i <= n; ++i)
	{
		int t = go_to(a, 0, i);
		for (int j = 1; j <= m; ++j)
		{
			t = r(a, t, 1);
			cout << a[t].value << " ";
		}
		cout << endl;
	}
}
int main()
{
	int n, m, q, i, j;
	cin >> n >> m >> q;
	vector<int> x1(q), y1(q), x2(q), y2(q), w(q), h(q);
	vector< vector< int > > A(n + 2);
	for (i = 0; i < n + 2; ++i) A[i].resize(m + 2);

	for (i = 1; i <= n; ++i)
	{
		for (j = 1; j <= m; ++j)
		{
			cin >> A[i][j];
		}
	}
	//Ввод координат прямоугольников
	for (i = 0; i < q; ++i)
	{
		cin >> x1[i] >> y1[i] >> x2[i] >> y2[i] >> w[i] >> h[i];
	}
	for (i = 0; i < n + 2; ++i)
	{
		for (j = 0; j < m + 2; ++j)
		{
			if (i == 0 || j == 0 || i == n + 1 || j == m + 1) A[i][j] = -1;
		}
	}
	for (i = 0; i < n + 2; ++i)
	{
		for (j = 0; j < m + 2; ++j)
		{
			//cout << A[i][j] << " ";
		}
		//cout << endl;
	}

	//Делаем из таблицы массив "a"
	vector <leave> a((m + 2)*(n + 2));
	for (i = 0; i < n + 2; ++i)
	{
		for (j = 0; j < m + 2; ++j)
		{
			a[(m + 2)*i + j].value = A[i][j];
		}
	}
	for (i = 0; i < n + 2; ++i)
	{
		for (j = 0; j < m + 2; ++j)
		{
			if (i != n + 1)
			{
				a[(m + 2)*i + j].lower = (m + 2)*i + j + m + 2;
			}
			else a[(m + 2)*i + j].lower = -1;
			if (j != m + 1)
			{
				a[(m + 2)*i + j].right = (m + 2)*i + j + 1;
			}
			else a[(m + 2)*i + j].right = -1;
		}
	}
	//cout << "Go_to =" << endl;
	//cout << go_to(a, 2, 4) << endl;
	//Замена прямоугольников
	for (i = 0; i < q; ++i)
	{
		change(a, x1[i], y1[i], x2[i], y2[i], w[i], h[i]);
		//print(a, n, m);
	}

	//cout << "Print" << endl;
	//print(a, n, m);
	//cout << "Value" << endl;
	for (i = 0; i < n + 2; ++i)
	{
		for (j = 0; j < m + 2; ++j)
		{
			//cout << a[(m + 2)*i + j].value << " ";
		}
		//cout << endl;
	}
	//cout << "Right" << endl;
	for (i = 0; i < n + 2; ++i)
	{
		for (j = 0; j < m + 2; ++j)
		{
			//cout << a[(m + 2)*i + j].right << " ";
		}
		//cout << endl;
	}
	//cout << "Lower" << endl;
	for (i = 0; i < n + 2; ++i)
	{
		for (j = 0; j < m + 2; ++j)
		{
			//cout << a[(m + 2)*i + j].lower << " ";
		}
		//cout << endl;
	}
	//cout << "R =" << endl;
	//cout << r(a, 0, 5) << endl;
	//cout << "D =" << endl;
	//cout << d(a, 0, 5) << endl;
	//cout << "Go_to =" << endl;
	//cout << go_to(a, 5, 5) << endl;

	//Финальный вывод
	print(a, n, m);
 	return 0;
}


#include<stdio.h>
#include<string.h>
#include<set>
using namespace std;
const int N=1010;
multiset<int> muls;
void swap1(int &a,int &b){a^=b^=a^=b;}
int id[N][N];//ID of position
int down[N*N],up[N*N],left[N*N],right[N*N];//ID,not position number
int lnd[2][N],lnu[2][N],lnl[2][N],lnr[2][N];//edge of submatrix
int chess[N*N];
int main()
{
	int n,m,q,i,j,a,b,c,d,tot=0,h,w;
	scanf("%d%d%d",&n,&m,&q);
	for(i=0;i<n+2;i++)for(j=0;j<m+2;j++)id[i][j]=tot++;
	for(i=1;i<n+1;i++)for(j=1;j<m+1;j++)scanf("%d",chess+id[i][j]);//�����1��ʼ����
	//cross link table init
	for(i=0;i<n+2;i++)for(j=0;j<m+1;j++)left[id[i][j+1]]=id[i][j],right[id[i][j]]=id[i][j+1];
	for(i=0;i<n+1;i++)for(j=0;j<m+2;j++)up[id[i+1][j]]=id[i][j],down[id[i][j]]=id[i+1][j];
	while(q--)
	{
		scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&h,&w);
		int x=id[0][0],y=id[0][0];
		for(i=0;i<a;i++)x=down[x];for(i=0;i<b;i++)x=right[x];
		for(i=0;i<c;i++)y=down[y];for(i=0;i<d;i++)y=right[y];
		int x1=x,y1=y;
		for(i=0;i<h;i++)
		{
			lnl[0][i]=x1,lnl[1][i]=y1;
			x1=down[x1],y1=down[y1];
		}
		x1=up[x1],y1=up[y1];
		for(i=0;i<w;i++)
		{
			lnd[0][i]=x1,lnd[1][i]=y1;
			x1=right[x1],y1=right[y1];
		}
		x1=x,y1=y;
		for(i=0;i<w;i++)
		{
			lnu[0][i]=x1,lnu[1][i]=y1;
			x1=right[x1],y1=right[y1];
		}
		x1=left[x1],y1=left[y1];
		for(i=0;i<h;i++)
		{
			lnr[0][i]=x1,lnr[1][i]=y1;
			x1=down[x1],y1=down[y1];
		}
		for(i=0;i<h;i++)
		{
			swap1(right[left[lnl[0][i]]],right[left[lnl[1][i]]]);
			swap1(left[lnl[0][i]],left[lnl[1][i]]);
			swap1(left[right[lnr[0][i]]],left[right[lnr[1][i]]]);
			swap1(right[lnr[0][i]],right[lnr[1][i]]);
		}
		for(i=0;i<w;i++)
		{
			swap1(up[down[lnd[0][i]]],up[down[lnd[1][i]]]);
			swap1(down[lnd[0][i]],down[lnd[1][i]]);
			swap1(down[up[lnu[0][i]]],down[up[lnu[1][i]]]);
			swap1(up[lnu[0][i]],up[lnu[1][i]]);
		}
	}
	int x0=id[0][0],u;
	for(i=1;i<n+1;i++)
	{
		x0=u=down[x0];
		for(j=1;j<m+1;j++)
		{
			u=right[u];
			printf("%d ",chess[u]);
		}
		puts("");
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<set>
using namespace std;
const int N=1010;
multiset<int> muls;
void swap1(int &a,int &b){a^=b^=a^=b;}
int id[N][N];//ID of position
int down[N*N],up[N*N],left[N*N],right[N*N];//ID,not position number
int lnd[2][N],lnu[2][N],lnl[2][N],lnr[2][N];//edge of submatrix
int chess[N*N];
int main()
{
	int n,m,q,i,j,a,b,c,d,tot=0,h,w;
	scanf("%d%d%d",&n,&m,&q);
	for(i=0;i<n+2;i++)for(j=0;j<m+2;j++)id[i][j]=tot++;
	for(i=1;i<n+1;i++)for(j=1;j<m+1;j++)scanf("%d",chess+id[i][j]);//�����1��ʼ����
	//cross link table init
	for(i=0;i<n+2;i++)for(j=0;j<m+1;j++)left[id[i][j+1]]=id[i][j],right[id[i][j]]=id[i][j+1];
	for(i=0;i<n+1;i++)for(j=0;j<m+2;j++)up[id[i+1][j]]=id[i][j],down[id[i][j]]=id[i+1][j];
	while(q--)
	{
		scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&h,&w);
		int x=id[0][0],y=id[0][0];
		for(i=0;i<a;i++)x=down[x];for(i=0;i<b;i++)x=right[x];
		for(i=0;i<c;i++)y=down[y];for(i=0;i<d;i++)y=right[y];
		int x1=x,y1=y;
		for(i=0;i<h;i++)
		{
			lnl[0][i]=x1,lnl[1][i]=y1;
			x1=down[x1],y1=down[y1];
		}
		x1=up[x1],y1=up[y1];
		for(i=0;i<w;i++)
		{
			lnd[0][i]=x1,lnd[1][i]=y1;
			x1=right[x1],y1=right[y1];
		}
		x1=x,y1=y;
		for(i=0;i<w;i++)
		{
			lnu[0][i]=x1,lnu[1][i]=y1;
			x1=right[x1],y1=right[y1];
		}
		x1=left[x1],y1=left[y1];
		for(i=0;i<h;i++)
		{
			lnr[0][i]=x1,lnr[1][i]=y1;
			x1=down[x1],y1=down[y1];
		}
		for(i=0;i<h;i++)
		{
			swap1(right[left[lnl[0][i]]],right[left[lnl[1][i]]]);
			swap1(left[lnl[0][i]],left[lnl[1][i]]);
			swap1(left[right[lnr[0][i]]],left[right[lnr[1][i]]]);
			swap1(right[lnr[0][i]],right[lnr[1][i]]);
		}
		for(i=0;i<w;i++)
		{
			swap1(up[down[lnd[0][i]]],up[down[lnd[1][i]]]);
			swap1(down[lnd[0][i]],down[lnd[1][i]]);
			swap1(down[up[lnu[0][i]]],down[up[lnu[1][i]]]);
			swap1(up[lnu[0][i]],up[lnu[1][i]]);
		}
	}
	int x0=id[0][0],u;
	for(i=1;i<n+1;i++)
	{
		x0=u=down[x0];
		for(j=1;j<n+1;j++)
		{
			u=right[u];
			printf("%d ",chess[u]);
		}
		puts("");
	}
	return 0;
}


// Программа выполнения работы Василия - человека, который
// работает на самой идиотской работе в мире
#include <stdio.h>
#include <iostream>		// Вывод в консоль
#include <tchar.h>
//#include <Windows.h>	// Библиотека Windows
using namespace std;

// Структура под задания Васи
struct Job {
	int x1, y1;		// Верхний угол первого прямоугольника
	int x2, y2;		// Верхний угол второго прямоугольника
	int w, h;		// Ширина и высота
};

int _tmain(int argc, _TCHAR* argv[])
{
	/*
	// А давайте включим русский, дети!
	setlocale(LC_ALL, "Russian");
	SetConsoleCP(1251);
	SetConsoleOutputCP(1251);

	// И воткнём другой шрифт, чтобы нормально отображались
	// русские символы
	CONSOLE_FONT_INFOEX info = { 0 };
	info.cbSize = sizeof(info);
	info.dwFontSize.Y = 14;
	info.FontWeight = FW_NORMAL;
	wcscpy_s(info.FaceName, L"Lucida Console");
	SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), NULL, &info);
	*/
	// Очистка входящего буффера
	cin.clear();
	fflush(stdin);

	// Ввод данных от пользователя
	//cout << "Введите высоту и ширину матрицы, а так же количество задач: ";
	int matrixWidth = 0, matrixHeight = 0, jobCount = 0;
	cin
		>> matrixHeight
		>> matrixWidth
		>> jobCount;

	// Делаем матрицу
	//cout << "Введите каждый элемент матрицы (" << matrixWidth << "x" << matrixHeight << "): " << endl;
	int sz = matrixWidth * matrixHeight;
	int* matrix = new int[sz];
	for (int i = 0; i < sz; i++) {
		cin >> matrix[i];
	}

	// Делаем массив задач
	Job* jobList = new Job[jobCount];
	for (int i = 0; i < jobCount; i++) {
		//cout << "Введите y1, x1, y2, x2, h, w для задачи номер "<< (i+1) <<": ";
		cin
			>> jobList[i].y1
			>> jobList[i].x1
			>> jobList[i].y2
			>> jobList[i].x2
			>> jobList[i].h
			>> jobList[i].w;
	}

	// А теперь - работаем

	// Заводим структуру, потому что так быстрее
	Job j;

	// Временные переменные
	// Задаём снаружи чтобы избежать аллокации памяти внутри цикла
	int height = 0;
	int width = 0;
	int heightDiff = 0;
	int row1 = 0;
	int row2 = 0;
	int col1 = 0;
	int col2 = 0;

	// Буффер создаём в начале работы, будет реюз
	void* buffer = malloc(matrixWidth * sizeof(int));
	for (int jc = 0; jc < jobCount; jc++) {

		// Скопировать в новую структуру гораздо проще, чем индексировать
		// массив большое количество раз
		// Так как оффсеты начинаются с единицы, уменьшаем их
		memcpy(&j, &jobList[jc], sizeof(Job));
		j.x1--;
		j.x2--;
		j.y1--;
		j.y2--;

		// Вычисляем разницу в высоте двух прямоугольников в байтах
		height = j.y1 + j.h;
		heightDiff = (j.y2 - j.y1) * matrixWidth;

		// Вычисляем размер строки в байтах
		width = j.w * sizeof(int);

		// Проходимся по строкам
		for (int r = j.y1; r < height; r++) {

			// Оффсеты строк и столбцов
			row1 = r * matrixWidth;
			row2 = row1 + heightDiff;
			col1 = row1 + j.x1;
			col2 = row2 + j.x2;

			// А давайте гонять память як школьник писюн!
			memcpy(buffer,			matrix + col1,	width);
			memcpy(matrix + col1,	matrix + col2,	width);
			memcpy(matrix + col2,	buffer,			width);
		}
	}

	// Вывод данных
	//cout << "Конечная матрица: " << endl;
	int col = 0;
	for (int i = 0; i < sz; i++) {
		cout << matrix[i] << " ";
		col++;
		if (col == matrixWidth) {
			col = 0;
			cout << endl;
		}
	}

	// Ждём Enter
	//system("pause");

	// Освобождаем нашу память
	free(buffer);
	delete[] jobList;
	delete[] matrix;
	return 0;
}


// Программа выполнения работы Василия - человека, который
// работает на самой идиотской работе в мире
//#include "stdafx.h"
#include <stdio.h>
#include <iostream>		// Вывод в консоль
#include <tchar.h>
//#include <Windows.h>	// Библиотека Windows
using namespace std;

// Структура под задания Васи
struct Job {
	int x1, y1;		// Верхний угол первого прямоугольника
	int x2, y2;		// Верхний угол второго прямоугольника
	int w, h;		// Ширина и высота
};

unsigned int matrix[1000000];
unsigned int * mp = &matrix[0];
Job jobList[10000];
unsigned int buffer[1000];
unsigned int * bp = &buffer[0];

int _tmain(int argc, _TCHAR* argv[])
{
	// Ввод данных от пользователя
	int matrixWidth = 0, matrixHeight = 0, jobCount = 0;
	scanf_s("%d%d%d", &matrixHeight, &matrixWidth, &jobCount);

	// Делаем матрицу
	int sz = matrixWidth * matrixHeight;
	for (int h = 0; h < matrixHeight; h++) {
		for (int w = 0; w < matrixWidth; w++) {
			scanf_s("%d", mp + h * 1000 + w);
		}
	}

	// Делаем массив задач

	Job jp;
	for (int i = 0; i < jobCount; i++) {
		scanf_s("%d%d%d%d%d%d", &jp.y1, &jp.x1, &jp.y2, &jp.x2, &jp.h, &jp.w);
		memcpy(&jobList[i], &jp, sizeof(Job));
	}

	// А теперь - работаем

	// Заводим структуру, потому что так быстрее
	Job j;

	// Временные переменные
	// Задаём снаружи чтобы избежать аллокации памяти внутри цикла
	int height = 0;
	int width = 0;
	int heightDiff = 0;
	//int widthDiff = 0;
	int row1 = 0;
	int row2 = 0;
	int col1 = 0;
	int col2 = 0;
	unsigned int * mp1, * mp2;
	unsigned int swp;

	for (int jc = 0; jc < jobCount; jc++) {

		// Скопировать в новую структуру гораздо проще, чем индексировать
		// массив большое количество раз
		// Так как оффсеты начинаются с единицы, уменьшаем их
		memcpy(&j, &jobList[jc], sizeof(Job));
		j.x1--;
		j.x2--;
		j.y1--;
		j.y2--;

		// Вычисляем разницу в высоте двух прямоугольников в байтах
		height = j.y1 + j.h;
		heightDiff = (j.y2 - j.y1) * 1000;

		// Вычисляем размер строки в байтах
		//width = j.w * sizeof(unsigned int);
		//widthDiff = j.x2 - j.x1;

		// Проходимся по строкам
		for (int r = j.y1; r < height; r++) {

			// Оффсеты строк и столбцов
			row1 = r * 1000;
			row2 = row1 + heightDiff;
			col1 = row1 + j.x1;
			col2 = row2 + j.x2;

			mp1 = &matrix[col1];
			mp2 = &matrix[col2];

			memcpy(bp, mp1, width);
			memcpy(mp1, mp2, width);
			memcpy(mp2, bp, width);
			//for (int c = 0; c < jobList[jc].w; c++) {
			//	swp = matrix[col1+c];
			//	matrix[col1+c] = matrix[col2+c];
			//	matrix[col2+c] = swp;
			//}
		}
	}

	// Вывод данных
	//cout << "Конечная матрица: " << endl;
	for (int h = 0; h < matrixHeight; h++) {
		for (int w = 0; w < matrixWidth; w++) {
			printf("%d ", matrix[h * 1000 + w]);
		}
		printf("\n");
	}

	//system("pause");
	return 0;
}


// Программа выполнения работы Василия - человека, который
// работает на самой идиотской работе в мире
//#include "stdafx.h"
#include <stdio.h>
#include <iostream>		// Вывод в консоль
#include <tchar.h>
//#include <Windows.h>	// Библиотека Windows
using namespace std;

// Структура под задания Васи
struct Job {
	int x1, y1;		// Верхний угол первого прямоугольника
	int x2, y2;		// Верхний угол второго прямоугольника
	int w, h;		// Ширина и высота
};

unsigned int matrix[1000000];
Job jobList[10000];
unsigned int buffer[1000];
unsigned int * bp = &buffer[0];

int _tmain(int argc, _TCHAR* argv[])
{
	ios::sync_with_stdio(false);
	// Ввод данных от пользователя
	int matrixWidth = 0, matrixHeight = 0, jobCount = 0;
	cin
		>> matrixHeight
		>> matrixWidth
		>> jobCount;

	// Делаем матрицу
	int sz = matrixWidth * matrixHeight;
	for (int h = 0; h < matrixHeight; h++) {
		for (int w = 0; w < matrixWidth; w++) {
			cin >> matrix[h * 1000 + w];
		}
	}

	// Делаем массив задач
	for (int i = 0; i < jobCount; i++) {
		cin
			>> jobList[i].y1
			>> jobList[i].x1
			>> jobList[i].y2
			>> jobList[i].x2
			>> jobList[i].h
			>> jobList[i].w;
	}

	// А теперь - работаем

	// Заводим структуру, потому что так быстрее
	Job j;

	// Временные переменные
	// Задаём снаружи чтобы избежать аллокации памяти внутри цикла
	int height = 0;
	int width = 0;
	int heightDiff = 0;
	//int widthDiff = 0;
	int row1 = 0;
	int row2 = 0;
	int col1 = 0;
	int col2 = 0;
	unsigned int * mp1, * mp2;

	for (int jc = 0; jc < jobCount; jc++) {

		// Скопировать в новую структуру гораздо проще, чем индексировать
		// массив большое количество раз
		// Так как оффсеты начинаются с единицы, уменьшаем их
		memcpy(&j, &jobList[jc], sizeof(Job));
		j.x1--;
		j.x2--;
		j.y1--;
		j.y2--;

		// Вычисляем разницу в высоте двух прямоугольников в байтах
		height = j.y1 + j.h;
		heightDiff = (j.y2 - j.y1) * 1000;

		// Вычисляем размер строки в байтах
		width = j.w * sizeof(unsigned int);
		//widthDiff = j.x2 - j.x1;

		// Проходимся по строкам
		for (int r = j.y1; r < height; r++) {

			// Оффсеты строк и столбцов
			row1 = r * 1000;
			row2 = row1 + heightDiff;
			col1 = row1 + j.x1;
			col2 = row2 + j.x2;

			mp1 = &matrix[col1];
			mp2 = &matrix[col2];

			memcpy(bp, mp1, width);
			memcpy(mp1, mp2, width);
			memcpy(mp2, bp, width);
		}
	}

	// Вывод данных
	//cout << "Конечная матрица: " << endl;
	for (int h = 0; h < matrixHeight; h++) {
		for (int w = 0; w < matrixWidth; w++) {
			cout << matrix[h * 1000 + w]<< " ";
		}
		cout << endl;
	}

	//system("pause");
	return 0;
}


// Программа выполнения работы Василия - человека, который
// работает на самой идиотской работе в мире
//#include "stdafx.h"
#include <stdio.h>
#include <iostream>		// Вывод в консоль
#include <tchar.h>
//#include <Windows.h>	// Библиотека Windows
using namespace std;

// Структура под задания Васи
struct Job {
	int x1, y1;		// Верхний угол первого прямоугольника
	int x2, y2;		// Верхний угол второго прямоугольника
	int w, h;		// Ширина и высота
};

unsigned int matrix[1000000];
Job jobList[10000];
unsigned int buffer[1000];
unsigned int * bp = &buffer[0];

int _tmain(int argc, _TCHAR* argv[])
{
	// Ввод данных от пользователя
	int matrixWidth = 0, matrixHeight = 0, jobCount = 0;
	scanf_s("%d%d%d", &matrixHeight, &matrixWidth, &jobCount);

	// Делаем матрицу
	int sz = matrixWidth * matrixHeight;
	for (int h = 0; h < matrixHeight; h++) {
		for (int w = 0; w < matrixWidth; w++) {
			scanf_s("%d", &matrix[h * 1000 + w]);
		}
	}

	// Делаем массив задач
	for (int i = 0; i < jobCount; i++) {
		scanf_s("%d%d%d%d%d%d", &jobList[i].y1, &jobList[i].x1, &jobList[i].y2, &jobList[i].x2, &jobList[i].h, &jobList[i].w);
	}

	// А теперь - работаем

	// Заводим структуру, потому что так быстрее
	//Job j;

	// Временные переменные
	// Задаём снаружи чтобы избежать аллокации памяти внутри цикла
	int height = 0;
	int width = 0;
	int heightDiff = 0;
	//int widthDiff = 0;
	int row1 = 0;
	int row2 = 0;
	int col1 = 0;
	int col2 = 0;
	unsigned int * mp1, * mp2;
	unsigned int swp;

	for (int jc = 0; jc < jobCount; jc++) {

		// Скопировать в новую структуру гораздо проще, чем индексировать
		// массив большое количество раз
		// Так как оффсеты начинаются с единицы, уменьшаем их
		//memcpy(&j, &jobList[jc], sizeof(Job));
		jobList[jc].x1--;
		jobList[jc].x2--;
		jobList[jc].y1--;
		jobList[jc].y2--;

		// Вычисляем разницу в высоте двух прямоугольников в байтах
		height = jobList[jc].y1 + jobList[jc].h;
		heightDiff = (jobList[jc].y2 - jobList[jc].y1) * 1000;

		// Вычисляем размер строки в байтах
		//width = j.w * sizeof(unsigned int);
		//widthDiff = j.x2 - j.x1;

		// Проходимся по строкам
		for (int r = jobList[jc].y1; r < height; r++) {

			// Оффсеты строк и столбцов
			row1 = r * 1000;
			row2 = row1 + heightDiff;
			col1 = row1 + jobList[jc].x1;
			col2 = row2 + jobList[jc].x2;

			//mp1 = &matrix[col1];
			//mp2 = &matrix[col2];

			//memcpy(bp, mp1, width);
			//memcpy(mp1, mp2, width);
			//memcpy(mp2, bp, width);
			for (int c = 0; c < j.w; c++) {
				swp = matrix[col1+c];
				matrix[col1+c] = matrix[col2+c];
				matrix[col2+c] = swp;
			}
		}
	}

	// Вывод данных
	//cout << "Конечная матрица: " << endl;
	for (int h = 0; h < matrixHeight; h++) {
		for (int w = 0; w < matrixWidth; w++) {
			printf("%d ", matrix[h * 1000 + w]);
		}
		printf("\n");
	}

	//system("pause");
	return 0;
}


// Программа выполнения работы Василия - человека, который
// работает на самой идиотской работе в мире
//#include "stdafx.h"
#include <stdio.h>
#include <iostream>		// Вывод в консоль
#include <tchar.h>
//#include <Windows.h>	// Библиотека Windows
using namespace std;

// Структура под задания Васи
struct Job {
	int x1, y1;		// Верхний угол первого прямоугольника
	int x2, y2;		// Верхний угол второго прямоугольника
	int w, h;		// Ширина и высота
};

int matrix[1000000];
int* mp = &matrix[0];
Job jobList[10000];

int _tmain(int argc, _TCHAR* argv[])
{
	cin.clear();
	fflush(stdin);

	// Ввод данных от пользователя
	int matrixWidth = 0, matrixHeight = 0, jobCount = 0;
	cin
		>> matrixHeight
		>> matrixWidth
		>> jobCount;

	// Делаем матрицу
	int sz = matrixWidth * matrixHeight;
	for (int i = 0; i < sz; i++) {
		cin >> matrix[i];
	}

	// Делаем массив задач
	for (int i = 0; i < jobCount; i++) {
		cin
			>> jobList[i].y1
			>> jobList[i].x1
			>> jobList[i].y2
			>> jobList[i].x2
			>> jobList[i].h
			>> jobList[i].w;
	}

	// А теперь - работаем

	// Заводим структуру, потому что так быстрее
	Job j;

	// Временные переменные
	// Задаём снаружи чтобы избежать аллокации памяти внутри цикла
	int height = 0;
	int width = 0;
	int heightDiff = 0;
	int row1 = 0;
	int row2 = 0;
	int col1 = 0;
	int col2 = 0;

	// Буффер создаём в начале работы, будет реюз
	unsigned int buffer[1000];
	unsigned int * bp = &buffer[0];
	for (int jc = 0; jc < jobCount; jc++) {

		// Скопировать в новую структуру гораздо проще, чем индексировать
		// массив большое количество раз
		// Так как оффсеты начинаются с единицы, уменьшаем их
		memcpy(&j, &jobList[jc], sizeof(Job));
		j.x1--;
		j.x2--;
		j.y1--;
		j.y2--;

		// Вычисляем разницу в высоте двух прямоугольников в байтах
		height = j.y1 + j.h;
		heightDiff = (j.y2 - j.y1) * 1000;

		// Вычисляем размер строки в байтах
		width = j.w * sizeof(unsigned int);

		// Проходимся по строкам
		for (int r = j.y1; r < height; r++) {

			// Оффсеты строк и столбцов
			row1 = r * 1000;
			row2 = row1 + heightDiff;
			col1 = row1 + j.x1;
			col2 = row2 + j.x2;

			// А давайте гонять память як школьник писюн!
			memcpy(bp, mp + col1, width);
			memcpy(mp + col1, mp + col2, width);
			memcpy(mp + col2, bp, width);
		}
	}

	// Вывод данных
	//cout << "Конечная матрица: " << endl;
	int col = 0;
	for (int i = 0; i < sz; i++) {
		cout << matrix[i] << " ";
		col++;
		if (col == matrixWidth) {
			col = 0;
			cout << endl;
		}
	}
	return 0;
}


// Программа выполнения работы Василия - человека, который
// работает на самой идиотской работе в мире
#include "stdafx.h"
#include <stdio.h>
#include <iostream>		// Вывод в консоль
#include <tchar.h>
//#include <Windows.h>	// Библиотека Windows
using namespace std;

// Структура под задания Васи
struct Job {
	int x1, y1;		// Верхний угол первого прямоугольника
	int x2, y2;		// Верхний угол второго прямоугольника
	int w, h;		// Ширина и высота
};

int _tmain(int argc, _TCHAR* argv[])
{
	cin.clear();
	fflush(stdin);

	// Ввод данных от пользователя
	int matrixWidth = 0, matrixHeight = 0, jobCount = 0;
	cin
		>> matrixHeight
		>> matrixWidth
		>> jobCount;

	// Делаем матрицу
	int matrix[1000000];
	int* mp = &matrix[0];
	int sz = matrixWidth * matrixHeight;
	for (int i = 0; i < sz; i++) {
		cin >> matrix[i];
	}

	// Делаем массив задач
	Job jobList[10000];
	for (int i = 0; i < jobCount; i++) {
		cin
			>> jobList[i].y1
			>> jobList[i].x1
			>> jobList[i].y2
			>> jobList[i].x2
			>> jobList[i].h
			>> jobList[i].w;
	}

	// А теперь - работаем

	// Заводим структуру, потому что так быстрее
	Job j;

	// Временные переменные
	// Задаём снаружи чтобы избежать аллокации памяти внутри цикла
	int height = 0;
	int width = 0;
	int heightDiff = 0;
	int row1 = 0;
	int row2 = 0;
	int col1 = 0;
	int col2 = 0;

	// Буффер создаём в начале работы, будет реюз
	unsigned int buffer[1000];
	unsigned int * bp = &buffer[0];
	for (int jc = 0; jc < jobCount; jc++) {

		// Скопировать в новую структуру гораздо проще, чем индексировать
		// массив большое количество раз
		// Так как оффсеты начинаются с единицы, уменьшаем их
		memcpy(&j, &jobList[jc], sizeof(Job));
		j.x1--;
		j.x2--;
		j.y1--;
		j.y2--;

		// Вычисляем разницу в высоте двух прямоугольников в байтах
		height = j.y1 + j.h;
		heightDiff = (j.y2 - j.y1) * 1000;

		// Вычисляем размер строки в байтах
		width = j.w * sizeof(unsigned int);

		// Проходимся по строкам
		for (int r = j.y1; r < height; r++) {

			// Оффсеты строк и столбцов
			row1 = r * 1000;
			row2 = row1 + heightDiff;
			col1 = row1 + j.x1;
			col2 = row2 + j.x2;

			// А давайте гонять память як школьник писюн!
			memcpy(bp, mp + col1, width);
			memcpy(mp + col1, mp + col2, width);
			memcpy(mp + col2, bp, width);
		}
	}

	// Вывод данных
	//cout << "Конечная матрица: " << endl;
	int col = 0;
	for (int i = 0; i < sz; i++) {
		cout << matrix[i] << " ";
		col++;
		if (col == matrixWidth) {
			col = 0;
			cout << endl;
		}
	}
	return 0;
}


// Программа выполнения работы Василия - человека, который
// работает на самой идиотской работе в мире
//#include "stdafx.h"
#include <stdio.h>
#include <iostream>		// Вывод в консоль
#include <tchar.h>
//#include <Windows.h>	// Библиотека Windows
using namespace std;

// Структура под задания Васи
struct Job {
	int x1, y1;		// Верхний угол первого прямоугольника
	int x2, y2;		// Верхний угол второго прямоугольника
	int w, h;		// Ширина и высота
};

int _tmain(int argc, _TCHAR* argv[])
{
	cin.clear();
	fflush(stdin);

	// Ввод данных от пользователя
	int matrixWidth = 0, matrixHeight = 0, jobCount = 0;
	cin
		>> matrixHeight
		>> matrixWidth
		>> jobCount;

	// Делаем матрицу
	unsigned int matrix[1000000];
	unsigned int* mp = &matrix[0];
	int sz = matrixWidth * matrixHeight;
	for (int i = 0; i < sz; i++) {
		cin >> matrix[i];
	}

	// Делаем массив задач
	Job jobList[10000];
	for (int i = 0; i < jobCount; i++) {
		cin
			>> jobList[i].y1
			>> jobList[i].x1
			>> jobList[i].y2
			>> jobList[i].x2
			>> jobList[i].h
			>> jobList[i].w;
	}

	// А теперь - работаем

	// Заводим структуру, потому что так быстрее
	Job j;

	// Временные переменные
	// Задаём снаружи чтобы избежать аллокации памяти внутри цикла
	int height = 0;
	int width = 0;
	int heightDiff = 0;
	int row1 = 0;
	int row2 = 0;
	int col1 = 0;
	int col2 = 0;

	// Буффер создаём в начале работы, будет реюз
	unsigned int buffer[1000];
	unsigned int * bp = &buffer[0];
	for (int jc = 0; jc < jobCount; jc++) {

		// Скопировать в новую структуру гораздо проще, чем индексировать
		// массив большое количество раз
		// Так как оффсеты начинаются с единицы, уменьшаем их
		memcpy(&j, &jobList[jc], sizeof(Job));
		j.x1--;
		j.x2--;
		j.y1--;
		j.y2--;

		// Вычисляем разницу в высоте двух прямоугольников в байтах
		height = j.y1 + j.h;
		heightDiff = (j.y2 - j.y1) * 1000;

		// Вычисляем размер строки в байтах
		width = j.w * sizeof(unsigned int);

		// Проходимся по строкам
		for (int r = j.y1; r < height; r++) {

			// Оффсеты строк и столбцов
			row1 = r * 1000;
			row2 = row1 + heightDiff;
			col1 = row1 + j.x1;
			col2 = row2 + j.x2;

			// А давайте гонять память як школьник писюн!
			memcpy(bp, mp + col1, width);
			memcpy(mp + col1, mp + col2, width);
			memcpy(mp + col2, bp, width);
		}
	}

	// Вывод данных
	//cout << "Конечная матрица: " << endl;
	int col = 0;
	for (int i = 0; i < sz; i++) {
		cout << matrix[i] << " ";
		col++;
		if (col == matrixWidth) {
			col = 0;
			cout << endl;
		}
	}
	return 0;
}


// Программа выполнения работы Василия - человека, который
// работает на самой идиотской работе в мире
//#include "stdafx.h"
#include <stdio.h>
#include <iostream>		// Вывод в консоль
#include <tchar.h>
//#include <Windows.h>	// Библиотека Windows
using namespace std;

// Структура под задания Васи
struct Job {
	int x1, y1;		// Верхний угол первого прямоугольника
	int x2, y2;		// Верхний угол второго прямоугольника
	int w, h;		// Ширина и высота
};

unsigned int matrix[1000000];
unsigned int * mp = &matrix[0];
Job jobList[10000];
unsigned int buffer[1000];
unsigned int * bp = &buffer[0];

int _tmain(int argc, _TCHAR* argv[])
{
	// Ввод данных от пользователя
	int matrixWidth = 0, matrixHeight = 0, jobCount = 0;
	scanf_s("%d%d%d", &matrixHeight, &matrixWidth, &jobCount);

	// Делаем матрицу
	int sz = matrixWidth * matrixHeight;
	for (int h = 0; h < matrixHeight; h++) {
		for (int w = 0; w < matrixWidth; w++) {
			scanf_s("%d", mp + h * 1000 + w);
		}
	}

	// Делаем массив задач

	Job jp;
	for (int i = 0; i < jobCount; i++) {
		scanf_s("%d%d%d%d%d%d", &jp.y1, &jp.x1, &jp.y2, &jp.x2, &jp.h, &jp.w);
		memcpy(&jobList[i], &jp, sizeof(Job));
	}

	// А теперь - работаем

	// Заводим структуру, потому что так быстрее
	Job j;

	// Временные переменные
	// Задаём снаружи чтобы избежать аллокации памяти внутри цикла
	int height = 0;
	int width = 0;
	int heightDiff = 0;
	//int widthDiff = 0;
	int row1 = 0;
	int row2 = 0;
	int col1 = 0;
	int col2 = 0;
	unsigned int * mp1, * mp2;
	unsigned int swp;

	for (int jc = 0; jc < jobCount; jc++) {

		// Скопировать в новую структуру гораздо проще, чем индексировать
		// массив большое количество раз
		// Так как оффсеты начинаются с единицы, уменьшаем их
		memcpy(&j, &jobList[jc], sizeof(Job));
		j.x1--;
		j.x2--;
		j.y1--;
		j.y2--;

		// Вычисляем разницу в высоте двух прямоугольников в байтах
		height = j.y1 + j.h;
		heightDiff = (j.y2 - j.y1) * 1000;

		// Вычисляем размер строки в байтах
		//width = j.w * sizeof(unsigned int);
		//widthDiff = j.x2 - j.x1;

		// Проходимся по строкам
		for (int r = j.y1; r < height; r++) {

			// Оффсеты строк и столбцов
			row1 = r * 1000;
			row2 = row1 + heightDiff;
			col1 = row1 + j.x1;
			col2 = row2 + j.x2;

			mp1 = mp + col1;
			mp2 = mp + col2;

			memcpy(bp, mp1, width);
			memcpy(mp1, mp2, width);
			memcpy(mp2, bp, width);
			//for (int c = 0; c < jobList[jc].w; c++) {
			//	swp = matrix[col1+c];
			//	matrix[col1+c] = matrix[col2+c];
			//	matrix[col2+c] = swp;
			//}
		}
	}

	// Вывод данных
	//cout << "Конечная матрица: " << endl;
	for (int h = 0; h < matrixHeight; h++) {
		for (int w = 0; w < matrixWidth; w++) {
			printf("%d ", matrix[h * 1000 + w]);
		}
		printf("\n");
	}

	//system("pause");
	return 0;
}