while (line=gets)!= '0000'
  n=line.to_i
  i=0
  while (n!=6174) do
    l=n.to_s.each_char.sort.join.to_i
    s=n.to_s.each_char.reverse.join.to_i
    n=l-s
    if n==0
      i=:NA
      break
    end
    i+=1
  end
  puts i
end