#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;

int a[6][6];

int main() {
    for (int i = 1; i <= 5; i++)
        for (int j = 1; j <= 5; j++)
            cin >> a[i][j];
    int n1, n2, x, y;
    cin >> n1 >> n2 >> x >> y;
    if (n1 == 1 && n2 == 2) {
        int a1[3], a2[3];
        for (int i = 0; i < 2; i++)a1[i] = a[x][y + i];
        for (int i = 0; i < 2; i++)a2[i] = a[x + 1][y + i];
        for (int i = x; i < x + 2; i++) {
          
            a[i][y ] = a2[i - x];
            a[i][y + 1] = a1[i - x];
        }
        for (int i = 1; i <= 5; i++) {
            for (int j = 1; j <= 5; j++) {
                cout << a[i][j] << " ";
            }
            cout << endl;
        }

    } else if (n1 == 1 && n2 == 3) {
        int a1[3], a2[3], a3[3];
        for (int i = 0; i < 3; i++)a1[i] = a[x][y + i];
        for (int i = 0; i < 3; i++)a2[i] = a[x + 1][y + i];
        for (int i = 0; i < 3; i++)a3[i] = a[x + 2][y + i];
        for (int i = x; i < x + 3; i++) {
            a[i][y] = a3[i - x];
            a[i][y + 1] = a2[i - x];
            a[i][y + 2] = a1[i - x];
        }
        for (int i = 1; i <= 5; i++) {
            for (int j = 1; j <= 5; j++) {
                cout << a[i][j] << " ";
            }
            cout << endl;
        }


    } else if (n1 == 2 && n2 == 2) {
        int a1[3], a2[3];
        for (int i = 0; i < 2; i++)a1[i] = a[x][y + i];
        swap(a1[0],a1[1]);
        for (int i = 0; i < 2; i++)a2[i] = a[x + 1][y + i];
        swap(a2[0],a2[1]);
        for (int i = x; i < x + 2; i++) {
            a[i][y] = a1[i - x];
            a[i][y + 1] = a2[i - x];
        }
        for (int i = 1; i <= 5; i++) {
            for (int j = 1; j <= 5; j++) {
                cout << a[i][j] << " ";
            }
            cout << endl;
        }



    } else if (n1 == 2 && n2 == 3) {
        int a1[3], a2[3], a3[3];
        for (int i = 0; i < 3; i++)a1[i] = a[x][y + i];
        swap(a1[0],a1[2]);
        for (int i = 0; i < 3; i++)a2[i] = a[x + 1][y + i];
        swap(a2[0],a2[2]);
        for (int i = 0; i < 3; i++)a3[i] = a[x + 2][y + i];
        swap(a3[0],a3[2]);
        for (int i = x; i < x + 3; i++) {
            a[i][y] = a1[i - x];
            a[i][y + 1] = a2[i - x];
            a[i][y + 2] = a3[i - x];
        }
        for (int i = 1; i <= 5; i++) {
            for (int j = 1; j <= 5; j++) {
                cout << a[i][j] << " ";
            }
            cout << endl;
        }


    }
}
// 64 位输出请用 printf("%lld")