AT_ndpc2026_d 紙幣

Description

In the AtCoder Kingdom, banknotes of denominations $ 1 $ yen, $ 10 $ yen, $ 100 $ yen, $ \dots $ , $ 10^{100} $ yen are used. Alice wants to pay $ N $ yen to Bob. Find the minimum possible total number of banknotes exchanged, which is the sum of: - the number of banknotes Alice gives to Bob, and - the number of banknotes Bob gives back as change. More precisely, for any integer $ M \geq N $ , consider: - the minimum number of banknotes needed to represent exactly $ M $ yen, and - the minimum number of banknotes needed to represent exactly $ M - N $ yen. Find the minimum possible value of their sum. You are given $ T $ test cases. Solve each of them.

Input Format

The input is given from standard input in the following format: > $ T $ $ \mathrm{case}_1 $ $ \mathrm{case}_2 $ $ \vdots $ $ \mathrm{case}_T $ Each test case is given in the following format: > $ N $

Output Format

Print $ T $ lines. For the $ i $ -th line, output the answer for the $ i $ -th test case.

Explanation/Hint

### Sample Explanation 1 In the first test case: - Alice pays $ 10 $ yen using one $ 10 $ -yen banknote, and - Bob returns $ 3 $ yen as change using three $ 1 $ -yen banknotes. In this case, the total number of banknotes exchanged is $ 4 $ , which is optimal. ### Constraints - $ 1 \leq T \leq 10^4 $ - $ 1 \leq N \leq 10^{18} $ - All input values are integers