data = [str(i+1)*4 for i in range(9)]

while True:

    n = input()

    if n == '0000': 

        break

    elif n in data:

        print('NA')

        continue

    c = 0

    while n != '6174':

        L = int(''.join(sorted(list(n), key=int, reverse=True)))

        S = int(''.join(sorted(list(n), key=int)))

        n = str(L-S).zfill(4)

        c += 1

    else:

        print(c)
data = [str(i+1)*4 for i in range(9)]

while True:

    n = input()

    if n == '0000': 

        break

    elif n in data:

        print('NA')

        continue

    c = 0

    while n != '6174':

        L = int(''.join(sorted(n, reverse=True)))

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

        n = str(L-S).zfill(4)

        c += 1

    else:

        print(c)
data = [str(i + 1) * 4 for i in range(9)]
while True:
    n = input()
    if n == "0000":
        break
    elif n in data:
        print("NA")
        continue
    c = 0
    while n != "6174":
        L = int("".join(sorted(list(n), key=int, reverse=True)))
        S = int("".join(sorted(list(n), key=int)))
        n = str(L - S).zfill(4)
        c += 1
    else:
        print(c)

data = [str(i + 1) * 4 for i in range(9)]
while True:
    n = input()
    if n == "0000":
        break
    elif n in data:
        print("NA")
        continue
    c = 0
    while n != "6174":
        L = int("".join(sorted(n, reverse=True)))
        S = int("".join(sorted(n)))
        n = str(L - S).zfill(4)
        c += 1
    else:
        print(c)

-        L = int("".join(sorted(list(n), key=int, reverse=True))) -        S = int("".join(sorted(list(n), key=int))) +        L = int("".join(sorted(n, reverse=True))) +        S = int("".join(sorted(n)))