while (line=gets)!= '0000'
  n=line.chomp.chars.map(&:to_i)
  l=n.sort.join().to_i
  s=n.reverse.join().to_i
  if l==s
    puts :NA
    continue
  end
  i=0
  while (n!=6174) do
    n=l-s
    i+=1
  end
  puts i
end