def goal?(amida,m,s)
  s == 1 + (amida.inject(m-1) do |s,i|
    if s>1 && i[s-1]=="1"
      s-1
    elsif i[s]=="1"
      s+1
    else
      s
    end
  end)
end

loop do
  n = gets.to_i
  break if n==0
  m,s,d = 3.times.map{ gets.to_i }
  amida = d.times.map{ gets.chomp }
  if goal?(amida,m,s)
    puts 0
    next
  end
  catch :find do
    amida.each_with_index do |a,i|
      n.times do |j|
        if "0#{a}0"[j,3]=="000"
          added = amida.dup
          b = a.dup
          b[j] = "1"
          added[i] = b
          if goal?(added,m,s)
            puts "#{i+1} #{j+1}"
            throw :find
          end
        end
      end
    end
    puts 1
  end
end