def bang(x,y)
  if @d[y] != nil
    if @d[y][x] == "1"
      @d[y][x] = "0"
      bang(x,y-3)
      bang(x,y-2)
      bang(x,y-1)
      bang(x,y+1)
      bang(x,y+2)
      bang(x,y+3)
      bang(x-3,y)
      bang(x-2,y)
      bang(x-1,y)
      bang(x+1,y)
      bang(x+2,y)
      bang(x+3,y)
    end
  end
end
n=gets.to_i
for i in 0..n-1
  a=gets
  @d = Array.new(9,"0")
  for j in 1..8
    @d[j] = gets.chomp.split(//).unshift("0")
  end
  bang(gets.to_i,gets.to_i)
  for l in 1..8
    for m in 1..8
      print @d[l][m]
    end
    puts ""
  end
end