#include <iostream>
using namespace std;
int main()
{
int a[15][10];
//= {{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,1,0,0},{0,0,0,0,0,0,1,0,0,0},{0,0,0,0,0,0,1,0,0,0},{1,1,1,0,0,0,1,1,1,1},{0,0,0,0,1,0,0,0,0,0}};
for(int i = 0; i < 15; i++){
for(int j = 0; j < 10; j++){
cin >> a[i][j];
}
}
int b[4][4];
//={{1,1,0,0},{0,1,1,0},{0,0,0,0},{0,0,0,0}};
for(int i = 0; i < 4; i++){
for(int j = 0; j < 4; j++){
cin >> b[i][j];
}
}
int initLocation=0;
cin >> initLocation;
int bLocation[4] = {5,5,5,5};
for(int i = 0; i < 4; i++){//panduan mei yi lie
for(int j = 3; j >= 0; j--){
//cout << j << endl;
// cout << b[j][i] << endl;
if(b[j][i] == 1){
bLocation[i] = 4- j;//cong xia wang sahng shu di ji ge
break;
}
}
}
int aLocation[4] = {16,16,16,16};
for(int i = 0; i < 4; i++){
for(int j = 0; j < 15; j++){
if(a[j][i + initLocation-1] == 1){
aLocation[i] = j + 1;//cong shang wang xia shu di ji ge
break;
}
}
}
/*for(int i = 0; i < 4; i++){
cout << bLocation[i] << " ";
}
cout << endl;
for(int i = 0; i < 4; i++){
cout << aLocation[i] << " ";
}
cout << endl;*/
int minorder = 4;
int min = INT_MAX;
//cout <<"INT_MAX "<< INT_MAX << endl;
for(int i = 0; i < 4; i++){
if(aLocation[i] != 5 && ((aLocation[i] + bLocation[i]) < min)){
min = aLocation[i] + bLocation[i];
minorder = i;//b[4-bLocation[minorder]][minorder]
//cout <<"minorder "<< minorder << endl;
}
}
//a[minorder + initLocation - 1][aLocation[i]-1] = 1; 12
//a[aLocation[i]-2][minorder + initLocation - 1] = 1; 0
//b[4-bLocation[i]][minorder] 0
//cout <<endl << minorder << endl;
//cout << "4-bLocation[i]" << 4-bLocation[minorder]<< endl;
//cout << "aLocation[i]-2" << aLocation[minorder]-2<< endl;
for(int i = 0; i < 4; i++){
for(int j = 0; j < 4; j++){
if(b[i][j] == 1){
//a[aLocation[i]-1][minorder + initLocation - 1] = 1;
//cout <<"4-bLocation[minorder]-aLocation[minorder]+2 "<< 4-bLocation[minorder]-aLocation[minorder]+2 << endl;
//cout <<"j+initLocation - 1 "<< j+initLocation -1<< endl;
a[i - (4-bLocation[minorder]-aLocation[minorder]+2)][j+initLocation-1]=1;
}
}
}
for(int i = 0; i < 15; i++){
for(int j = 0; j < 10; j++){
cout << a[i][j] << " ";
}
cout << endl;
}
return 0;
}
using namespace std;
int main()
{
int a[15][10];
//= {{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,1,0,0},{0,0,0,0,0,0,1,0,0,0},{0,0,0,0,0,0,1,0,0,0},{1,1,1,0,0,0,1,1,1,1},{0,0,0,0,1,0,0,0,0,0}};
for(int i = 0; i < 15; i++){
for(int j = 0; j < 10; j++){
cin >> a[i][j];
}
}
int b[4][4];
//={{1,1,0,0},{0,1,1,0},{0,0,0,0},{0,0,0,0}};
for(int i = 0; i < 4; i++){
for(int j = 0; j < 4; j++){
cin >> b[i][j];
}
}
int initLocation=0;
cin >> initLocation;
int bLocation[4] = {5,5,5,5};
for(int i = 0; i < 4; i++){//panduan mei yi lie
for(int j = 3; j >= 0; j--){
//cout << j << endl;
// cout << b[j][i] << endl;
if(b[j][i] == 1){
bLocation[i] = 4- j;//cong xia wang sahng shu di ji ge
break;
}
}
}
int aLocation[4] = {16,16,16,16};
for(int i = 0; i < 4; i++){
for(int j = 0; j < 15; j++){
if(a[j][i + initLocation-1] == 1){
aLocation[i] = j + 1;//cong shang wang xia shu di ji ge
break;
}
}
}
/*for(int i = 0; i < 4; i++){
cout << bLocation[i] << " ";
}
cout << endl;
for(int i = 0; i < 4; i++){
cout << aLocation[i] << " ";
}
cout << endl;*/
int minorder = 4;
int min = INT_MAX;
//cout <<"INT_MAX "<< INT_MAX << endl;
for(int i = 0; i < 4; i++){
if(aLocation[i] != 5 && ((aLocation[i] + bLocation[i]) < min)){
min = aLocation[i] + bLocation[i];
minorder = i;//b[4-bLocation[minorder]][minorder]
//cout <<"minorder "<< minorder << endl;
}
}
//a[minorder + initLocation - 1][aLocation[i]-1] = 1; 12
//a[aLocation[i]-2][minorder + initLocation - 1] = 1; 0
//b[4-bLocation[i]][minorder] 0
//cout <<endl << minorder << endl;
//cout << "4-bLocation[i]" << 4-bLocation[minorder]<< endl;
//cout << "aLocation[i]-2" << aLocation[minorder]-2<< endl;
for(int i = 0; i < 4; i++){
for(int j = 0; j < 4; j++){
if(b[i][j] == 1){
//a[aLocation[i]-1][minorder + initLocation - 1] = 1;
//cout <<"4-bLocation[minorder]-aLocation[minorder]+2 "<< 4-bLocation[minorder]-aLocation[minorder]+2 << endl;
//cout <<"j+initLocation - 1 "<< j+initLocation -1<< endl;
a[i - (4-bLocation[minorder]-aLocation[minorder]+2)][j+initLocation-1]=1;
}
}
}
for(int i = 0; i < 15; i++){
for(int j = 0; j < 10; j++){
cout << a[i][j] << " ";
}
cout << endl;
}
return 0;
}