def hit(n, m, goal, d, dans)
  h = 0
  until h == d
    yoko = dans[h]
    if m != n - 1 and yoko[m] == 1
      m += 1
    elsif m.nonzero? and yoko[m - 1] == 1
      m -= 1
    end
    h += 1
  end
  goal == m
end

until (n = $<.gets.to_i).zero?
  m    = $<.gets.to_i - 1
  goal = $<.gets.to_i - 1
  d    = $<.gets.to_i
  dans = Array.new(d) { $<.gets.chomp.chars.map(&:to_i) }
  output = if hit(n, m, goal, d, dans)
    0
  else
    result = catch(:jump) do
      d.times do |h|
        (n - 1).times do |x|
          f = [-1, 0, 1].map do |dx|
            a = dans[h][x + dx]
            a ? a.zero? : nil
          end.compact.all?
          if f
            dans[h][x] = 1
            throw(:jump, [h + 1, x + 1]) if hit(n, m, goal, d, dans)
            dans[h][x] = 0
          end
        end
      end
      result = false
    end
    result ? "#{result[0]} #{result[1]}" : 1
  end
  puts output
end

