#include <iostream>
#include <string>
#include <vector>
using namespace std;

template<class T>class Array2D
{
private:
	T* mArray;
	int mSize0;
	int mSize1;
public:
	Array2D():mArray(0)
	{
		mSize0 = mSize1 = 0;
	}
	~Array2D()
	{
		delete[] mArray;
		mArray = 0;
	}
	void setSize(int size0,int size1)
	{
		mSize0 = size0;
		mSize1 = size1;
		mArray = new T[size0*size1];
	}
	T& operator () (int index0, int index1) {
		return mArray[index0 + index1*mSize0];
	}
};

int* search(Array2D<string>& table,int* point )
{
	int result[2];
	int target[2];
	target[0] = point[0];
	target[1] = point[1];
	//Array2D<string>& table_ = table;

	//cout << "point = " << point[0] << "," << point[1] << endl;

	for(int i=0;i<4;++i)
	{
		for(int k=1;k<4;++k)
		{
			target[0] = point[0];
			target[1] = point[1];
			switch(i)
			{
			case 0:
				target[1] -= k;
				break;
			case 1:
				target[0] += k;
				break;
			case 2:
				target[1] += k;
				break;
			case 3:
				target[0] -= k;
				break;
			}
			if (target[0] < 0)
				target[0] = 0;
			if (target[0] > 7)
				target[0] = 7;
			if (target[1] < 0)
				target[1] = 0;
			if (target[1] > 7)
				target[1]= 7;
			//cout << "target = " << target[0] << "," << target[1] << endl;

			if(table(target[0],target[1])=="1")
			{
				//cout << "Found:" << target[0] << "," << target[1] << endl;
				table(target[0], target[1]) = "0";
				search(table, target);
			}
		}
	}

	return result;
}


int main()
{

	int data_num = 0;
	cin >> data_num;

	


	//vector<string> table(64);

	Array2D<string> table;
	table.setSize(8, 8);
	string read;
	int point[2];

	for(int i=1;i<data_num+1;++i)
	{

		for(int k=0;k<8;++k)
		{
			cin >> read;
			for(int j=0;j<8;++j)
			{
				table(j,k) = read.at(j);
			}
		}

		cin >> point[0] >> point[1];
		point[0] --;
		point[1] --;

		cout << table(point[0],point[1]) << endl;
		
		search(table,point);
		//cout << "fin" << endl;
			
		
		cout << "Data " << i << ":" << endl;
		for (int k = 0; k<8; ++k)
		{
			for (int j = 0; j<8; ++j)
			{
				cout << table(j, k);
			}
			cout << endl;
		}

		
	}

	string endofprogram;
	cin >> endofprogram;
}