#include <iostream>

using namespace std;

bool field[9][9];

void vis(int x, int y){

	if(x<0 || 8<x || y<0 || 8<y || field[y][x]==0){
		return;
	}

	if(field[y][x]==1){

		field[y][x]=0;

		for(int t=1; t<=3; ++t){
		
			vis(x+t, y);
			vis(x-t, y);
			vis(x, y+t);
			vis(x, y-t);
		}
	}

	return;
}
		


int main(){

	int n, x, y;

	cin>>n;

	while(n--){
		
		for(int j=0; j<8; ++j){
			for(int i=0; i<8; ++i){

				char c;
				cin>>c;
				field[y][x]=c=='1';
			}
		}

		cin>>x>>y;
		vis(x, y);

		for(int j=0; j<8; ++j){
			for(int i=0; i<8; ++i){

				cout<<field[y][x];
			}

			cout << endl;
		}

		return 0;
}