atcoder#ARC123C. [ARC123C] 1, 2, 3 - Decomposition

[ARC123C] 1, 2, 3 - Decomposition

Score : 600600 points

Problem Statement

Given is a positive integer NN. Consider a sequence of integers A=(A1,,AK)A = (A_1, \ldots, A_K) that satisfies the conditions below:

  • i=1KAi=N\sum_{i=1}^K A_i = N;
  • each AiA_i is a positive integer such that every digit in its decimal notation is 11, 22, or 33.

Find the minimum possible value of KK, that is, the number of elements in such a sequence AA.

Process TT test cases per input file.

Constraints

  • 1T10001\leq T\leq 1000
  • 1N10181\leq N\leq 10^{18}

Input

Input is given from Standard Input in the following format:

TT

case1\text{case}_1

case2\text{case}_2

\vdots

caseT\text{case}_T

Each case is in the following format:

NN

Output

Print the answers.

5
456
10000
123
314
91
2
4
1
2
4

For each NN, one optimal AA is shown below.

  • For N=456N = 456: A=(133,323)A = (133, 323).
  • For N=10000N = 10000: A=(323,3132,3232,3313)A = (323, 3132, 3232, 3313).
  • For N=123N = 123: A=(123)A = (123).
  • For N=314N = 314: A=(312,2)A = (312,2).
  • For N=91N = 91: A=(22,23,23,23)A = (22,23,23,23).