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
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	
	public static int[] out = new int[]{0000, 1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999};
	public static int[] dir = new int[]{1000, 100, 10, 1};
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while(true){
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}else{
				boolean flag = false;
				for(int i : out){
					if(n == i){
						System.out.println("NA");
						flag = true;
						break;
					}
				}
				
				if(flag){
					continue;
				}
			}
			
			int count = 0;
			int cur = n;
			while(cur != 6174){				
				ArrayList<Integer> upper = new ArrayList<Integer>();
				ArrayList<Integer> downer = new ArrayList<Integer>();
				
				for(int i = 0; i < dir.length; i++){
					upper.add((cur / dir[i]) % 10);
					downer.add((cur / dir[i]) % 10);
				}
				
				Collections.sort(upper);
				Collections.sort(downer, Collections.reverseOrder());
				
				//System.out.println(upper);
				//System.out.println(downer);
				
				int up = 0, down = 0;
				for(int i = 0; i < dir.length; i++){
					up += upper.get(i) * dir[i];
					down += downer.get(i) * dir[i];
				}
				
				cur = down - up;
				count++;
				
				if(cur == 6174){
					break;
				}
			}
			
			System.out.println(count);
		}
		
		sc.close();
	}
}