while 1:

	n=list(input())

	if n==["0"]*4: break

	elif n[0]==n[1]==n[2]==n[3]:

		print("NA")

		continue

	count=0

	while 1:

		if n==["6","1","7","4"]:

			print(count)

			break

		n=sorted(n)

		l=int("".join(map(str,n[::-1])))

		s=int("".join(map(str,n[n.count("0"):])))

		n=list(str(l-s))

		n=["0"]*(4-len(n))+n

		count+=1
while 1:

    n=input()

    if n=="0000": break

    if int(n)%1111==0:

        print("NA")

        continue

    ans = 0

    while n!="6174":

        n="".join(sorted(n))

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

        ans+=1

    print(ans)
while 1:
    n = list(input())
    if n == ["0"] * 4:
        break
    elif n[0] == n[1] == n[2] == n[3]:
        print("NA")
        continue
    count = 0
    while 1:
        if n == ["6", "1", "7", "4"]:
            print(count)
            break
        n = sorted(n)
        l = int("".join(map(str, n[::-1])))
        s = int("".join(map(str, n[n.count("0") :])))
        n = list(str(l - s))
        n = ["0"] * (4 - len(n)) + n
        count += 1

while 1:
    n = input()
    if n == "0000":
        break
    if int(n) % 1111 == 0:
        print("NA")
        continue
    ans = 0
    while n != "6174":
        n = "".join(sorted(n))
        n = str(int(n[::-1]) - int(n)).zfill(4)
        ans += 1
    print(ans)

-    n = list(input()) -    if n == ["0"] * 4: +    n = input() +    if n == "0000": -    elif n[0] == n[1] == n[2] == n[3]: +    if int(n) % 1111 == 0: -    count = 0 -    while 1: -        if n == ["6", "1", "7", "4"]: -            print(count) -            break -        n = sorted(n) -        l = int("".join(map(str, n[::-1]))) -        s = int("".join(map(str, n[n.count("0") :]))) -        n = list(str(l - s)) -        n = ["0"] * (4 - len(n)) + n -        count += 1 +    ans = 0 +    while n != "6174": +        n = "".join(sorted(n)) +        n = str(int(n[::-1]) - int(n)).zfill(4) +        ans += 1 +    print(ans)