#P9354. 「SiR-1」Popsicle

「SiR-1」Popsicle

Background

However, how can one slack off elegantly?

Problem Description

Kitty has several popsicle sticks arranged in a row. Each stick has a digit from 090 \sim 9, and it is guaranteed that the digit on the leftmost stick is not 00. Kitty thinks that these sticks, from left to right, form a decimal positive integer nn.

Kitty thinks 00 is wonderful, so she will try her best to turn nn into 00, that is, remove all popsicle sticks.

Each time, Kitty performs one operation. In each operation, she chooses a popsicle stick whose digit is not 00, and decreases it by 11. After that, if there are some consecutive popsicle sticks on the far left whose digits are 00 (that is, nn has leading zeros), Kitty will remove those sticks.

A little mouse will come and cause trouble. At some moment (possibly before all operations start, or possibly after any one of Kitty's operations), it will change one digit on one popsicle stick. The little mouse can change only one digit in total.

The mouse wants the number of operations to be as large as possible, while Kitty wants it to be as small as possible. Therefore, Kitty wants to know the number of operations when both of them use optimal strategies.

Input Format

This problem contains multiple test cases in a single test file.

The first line contains a positive integer TT, the number of test cases. For each test case:

  • One line containing a positive integer nn.

Output Format

Output TT lines. Each line contains one integer, the answer.

2
1100
11332132121
11
28

Hint

Sample Explanation 1

For the first test case, the mouse can change 11001100 into 11091109 at the very beginning. Then Kitty needs a total of 1+1+91 + 1 + 9 operations to turn nn into 00.

Constraints

This problem uses bundled testdata.

  • Subtask 0 (13 pts): n99n \leq 99.
  • Subtask 1 (13 pts): n=10kn = 10^k, where kk is a natural number.
  • Subtask 2 (13 pts): n=10k1n = 10^k - 1, where kk is a positive integer.
  • Subtask 3 (13 pts): n999 999n \leq 999\ 999.
  • Subtask 4 (48 pts): No special restrictions.

For all testdata, 1T33331 \leq T \leq 3333, 1n9 999 999 999 999(=10131)1 \leq n \leq 9\ 999\ 999\ 999\ 999(=10^{13} - 1). After all, Kitty can have at most 1313 popsicle sticks in one bundle.

Translated by ChatGPT 5