p00254 All Numbers Lead to 6174
Do the following for a four-digit number N consisting of numbers 0-9.

1. Let L be the number obtained as a result of arranging the numerical values ​​of each of the N digits in descending order.
2. Let S be the number obtained as a result of arranging the numerical values ​​of each of the N digits in ascending order.
3. Let the difference L-S be the new N (end of one operation)
4. Repeat from 1. for the new N



At this time, it is known that any four-digit number will eventually become 6174, unless all digits are the same number (0000, 1111, etc.). For example, when N = 2012
First time (N = 2012): L = 2210, S = 0122, L-S = 2088
Second time (N = 2088): L = 8820, S = 0288, L-S = 8532
Third time (N = 8532): L = 8532, S = 2358, L-S = 6174
And reach 6174 in 3 operations.

Write a program that calculates how many operations will reach 6174 given a four-digit number consisting of the numbers 0-9.



input

The input consists of multiple datasets. The end of the input is indicated by 0000 on one line. Each dataset is given in the following format:


N


The dataset is one line and N (1 ≤ N ≤ 9999) indicates a four-digit number. If N <1000, the upper digit is padded with zeros.

The number of datasets does not exceed 10000.

output

The number of operations to reach 6174 for each data set is output on one line. However, if a number with all the same digits is given as input, NA is output.

Example

Input

6174
2012
3333
0000


Output

0
3
NA
```python
while True:
    number=int(input())
    if number==0000:
            break
    trial=0
    while True:
        if number==6174:
            print(trial)
            break
        box=[]
        for i in range(4):
            a=number%10
            number=int(number/10)
            box.append(a)
        if box[0]==box[1] and box[2]==box[3] and box[1]==box[2]:
            print("NA")
            break
        box.sort()
        l=0
        
        for i in range(4):
            l+=box[i]*10**i
        box.sort(reverse=True)
        s=0
        for i in range(4):
            s+=box[i]*10**i
        number=l-s
        trial+=1

```