def sweep(field, i, j)
  return field unless i.between?(0, 7)
  return field unless j.between?(0, 7)

  if field[j][i] == '1'
    field[j][i] = '0'
    1.upto(3) do |l|
      field = sweep(field, i + l, j)
      field = sweep(field, i - l, j)
      field = sweep(field, i, j + l)
      field = sweep(field, i, j - l)
    end
  end
  field
end
gets.to_i.times do |num|
  gets
  field = []
  8.times do
    field << gets.strip.split('')
  end
  i = gets.to_i - 1
  j = gets.to_i - 1
  field = sweep(field, i, j)
  puts "Data #{num + 1}:"
  field.each do |line|
    puts line.join
  end
end

