#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }

typedef long long ll;
typedef double D;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }


int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};


void solve(vcs& board, int bi, int bj) {
	board[bi][bj] = '0';
	
	for_(d, 0, 4) {
		int ni = bi + dx[d], nj = bj + dx[d];
		for_(k, 1, 4) {
			int ni_ = ni*k, nj_ = nj*k;
			if (ni_<0 || ni_>=8 || nj_<0 || nj_>=8) continue;
			
			if (board[ni_][nj_]=='1') solve(board, ni_, nj_);
		}
	}
}

int main() {
	int n; cin >> n;
	
	for_(i, 0, n) {
		int nul; cin>>nul;
		
		vcs board(8);
		for_(j, 0, 8) cin>>board[j];
		
		int bi, bj; cin>>bi>>bj;
		
		solve(board, bi, bj);
		for_(j, 0, 8) cout << board[i] << endl;
	}
	
	return 0;
}