def f;gets.to_i;end
while(n = f)>0
  m,g = f, f
  a = (1..n).to_a
  b = [a.dup]
  l = (1..f).map{
  i=0
  (r=gets.chars).map{|c|c>?0&&(*a[i,2]=a[i+1],a[i])
    i+=1}
    b<<a.dup
    r
}
  x=y=0
  puts m==(s=a[g-1])?0:l.find{|r|r=[?0]+r
  x+=1
  y=(1..n-1).find{|j|r[j-1,3].all?{|k|k<?1}&&b[x-1][j-1,2]-[m,s]==[]}}?"#{x} #{y}":1
end