def amida(n,m,s,l)
  a=Array.new(n) {|i| i+1}
  l.each do |i|
    # puts "#{i.join}"
    i.each_with_index do |j,id|
      a[id],a[id+1]=a[id+1],a[id] if j==1
    end
  end
  # p a
  # puts "m:#{m}, s:#{s}"
  return a[s-1]==m ? true : false
end

loop do
  break if gets.chomp=="0"
  n,m,s,d,l=$_.to_i,gets.to_i,gets.to_i,gets.to_i,[]
  # puts "#{n},#{m},#{s},#{d}"
  d.times do
    l<<gets.chomp.split("").map(&:to_i)
  end
  # puts "m:#{m}, s:#{s}"
  if amida(n,m,s,l) then puts 0
  else
    bf=false
    ll= Marshal.load(Marshal.dump(l))
    l.each_with_index do |i, idi|
      #0010???0111??¨???????????????1?????£???0???1??¨??´??°??????0111?????????each??§0?????´???1?????????(0010???1010)??????????????????????????????
      i.each_with_index do |j, idj|
        if j==1 then
          ll[idi][[0,idj-1].max]=1
          ll[idi][idj]=1
          ll[idi][[n-2,idj+1].min]=1
        end
      end
    end
    # p ll
    ll.each_with_index do |i, idi|
      i.each_with_index do |j, idj|
        # puts "i:#{idi},j:#{idj}" if j==0
        if j==0 then
          l3= Marshal.load(Marshal.dump(l))
          l3[idi][idj]=1
          puts "#{idi+1} #{idj+1}" if bf=amida(n,m,s,l3)
        end
      end
      break if bf
    end
    puts 1 unless bf
  end
end