Perform the following operations on a four-digit number N consisting of the digits 0 through 9.
In this case, it is known that every four-digit number will be 6174 at some point, except when all digits are the same (0000, 1111, etc.). For example, if N = 2012
1st. (N = 2012): L = 2210, S = 0122, L-S = 2088
2nd. (N = 2088): L = 8820, S = 0288, L-S = 8532
3rd. (N = 8532): L = 8532, S = 2358, L-S = 6174
and the value reaches 6174 in three operations.
Given a four-digit number from 0 to 9, write a program to calculate how many operations it takes to reach 6174.
The input consists of multiple data sets. The end of the input is indicated by a single line 0000. Each data set is given in the following format.
N
The data set is a single line, where N (1 ≤ N ≤ 9999) denotes a four-digit number. if N < 1000, the upper digits are filled with zeros.
The number of datasets does not exceed 10000.
For each data set, output the number of operations required to reach 6174 on a single line. However, if a number in which all digits are the same is given as input, the output should be "NA".
6174 2012 3333 0000
0 3 NA