Explosion = (-3..3).map{|i| [[i,0], [0,i]]}.flatten(1) - [[0, 0]]

def bomb(x, y)
	@field[y][x] = "0"
	Explosion.each do |dx, dy|
		nextX = x + dx
		nextY = y + dy
		next if !(0..7).include?(nextX) || !(0..7).include?(nextY)
		if @field[nextY][nextX] == "1"
			bomb(nextX, nextY)
		end
		@field[nextY][nextX] = "0"
	end
end

gets.to_i.times do |dataset|
	gets
	@field = 8.times.map{ gets.chomp }
	x, y = 2.times.map{ gets.to_i - 1 }
	bomb(x, y)
	puts "Data #{dataset+1}:"
	puts @field.join("\n")
end