On the board, the number is initially written. Every second, Petryk can perform one of two operations on this number:
- Add to the number. - Rearrange its digits in any order (the first digit must not be zero).
After performing an operation, Petryk erases the old number and writes the resulting new number on the board.
Task
Write a program to determine the minimum number of operations Petryk needs to reach a given natural number, starting from .
The first line contains a single integer (1 \leq T < 10^4), the number of queries. Each of the next lines contains a single natural number N_i (2 \leq N_i < 10^9, 1 \leq i \leq T). All N_i are distinct.
Print lines, one for each query. For the -th query, output the minimum number of seconds required for Petryk to write N_i on the board, starting from .
Örnek 1
The testset consists of 4 groups: 1. 25 points: 2 \leq N_i < 100 for all . 2. 25 points: T = 1; 100 \leq N_1 < 10^4. 3. 15 points: T > 1; 100 \leq N_i < 10^4 for all . 4. 35 points: 10^4 \leq N_i < 10^9 for all .