n = gets.to_i
m = gets.to_i
g = gets.to_i
d = gets.to_i
b = d.times.map{gets.chomp.chars.map(&:to_i)}

map = Array.new(d+1){Array.new(n,0)}
n.times do |i|
  map[0][i] = i+1
end

d.times do |j|
  n.times do |i|
    if i<n && b[j][i] == 1 
      map[j+1][i] = map[j][i+1]
    elsif i>0 && b[j][i-1] == 1
      map[j+1][i] = map[j][i-1]
    else
      map[j+1][i] = map[j][i]
    end
  end
end

puts map.map{|x| x*' '}*"\n"
if map[d][g-1] == m
  puts 0
elsif
  k = map[d][g-1]

  (d-1).times do |j|
    i = map[j].find_index(m)
    if i<n && b[j][i] == 0 && (i<=0 || b[j][i-1] == 0) && (i>=n-2 || b[j][i+1] == 0)
      if map[j][i+1] == k
        puts [j+1, i+1].join(' ')
        exit()
      end
    elsif i>0 && b[j][i-1] == 0 && (i>=n || b[j][i] == 0) && (i<2 || b[j][i-2] == 0)
      if map[j][i-1] == k
        puts [j+1, i].join(' ')
        exit()
      end
    end
  end

  puts '1'
end