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) }
  
  if hit(n, m, goal, d, dans)
    puts 0
  else
    try = ->{
      d.times do |h|
        ([0] + dans[h] + [0]).each_cons(3).with_index do |a, x|
          if a.sum.zero?
            dans[h][x] = 1
            return "#{h + 1} #{x + 1}" if hit(n, m, goal, d, dans)
            dans[h][x] = 0
          end
        end
      end
      1
    }
    puts try.()
  end
end
