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],a[i+1]=a[i+1],a[i]);i+=1}
b<<a.dup
r
}
y=x=0
puts m==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,a[g-1]]==[])}
}?"#{x} #{y}":1
end