while 1:

    n,c=eval(input()),0

    if int(n)==0:break

    if n.count(n[0])==4:

        print('NA')

        continue

    while n!='6174':

        n = str(int(''.join(reversed(sorted(list(n))))) - int(''.join(sorted(list(n))))).zfill(4)

        c+=1

    print(c)
while 1:

    n,c=eval(input()),0

    if int(n)==0:break

    if n.count(n[0])==4:

        print('NA')

        continue

    while n!='6174':

        n=''.join(sorted(n))

        n = str(int(n[::-1]) - int(n)).zfill(4)

        c+=1

    print(c)
while 1:
    n, c = eval(input()), 0
    if int(n) == 0:
        break
    if n.count(n[0]) == 4:
        print("NA")
        continue
    while n != "6174":
        n = str(
            int("".join(reversed(sorted(list(n))))) - int("".join(sorted(list(n))))
        ).zfill(4)
        c += 1
    print(c)

while 1:
    n, c = eval(input()), 0
    if int(n) == 0:
        break
    if n.count(n[0]) == 4:
        print("NA")
        continue
    while n != "6174":
        n = "".join(sorted(n))
        n = str(int(n[::-1]) - int(n)).zfill(4)
        c += 1
    print(c)

-        n = str( -            int("".join(reversed(sorted(list(n))))) - int("".join(sorted(list(n)))) -        ).zfill(4) +        n = "".join(sorted(n)) +        n = str(int(n[::-1]) - int(n)).zfill(4)