CF2093B.Expensive Number

传统题 时间 2000 ms 内存 256 MiB 4 尝试 1 已通过 1 标签

Expensive Number

The cost of a positive integer nn is defined as the result of dividing the number nn by the sum of its digits.

For example, the cost of the number 104104 is 1041+0+4=20.8\frac{104}{1 + 0 + 4} = 20.8, and the cost of the number 111111 is 1111+1+1=37\frac{111}{1 + 1 + 1} = 37.

You are given a positive integer nn that does not contain leading zeros. You can remove any number of digits from the number nn (including none) so that the remaining number contains at least one digit and is strictly greater than zero. The remaining digits cannot be rearranged. As a result, you may end up with a number that has leading zeros.

For example, you are given the number 103554103554. If you decide to remove the digits 11, 44, and one digit 55, you will end up with the number 035035, whose cost is 0350+3+5=4.375\frac{035}{0 + 3 + 5} = 4.375.

What is the minimum number of digits you need to remove from the number so that its cost becomes the minimum possible?

Input

The first line contains an integer tt (1t10001 \leq t \leq 1000) — the number of test cases.

The only line of each test case contains a positive integer nn (1n<101001 \leq n \lt 10^{100}) without leading zeros.

Output

For each test case, output one integer on a new line — the number of digits that need to be removed from the number so that its cost becomes minimal.

Samples

4
666
13700
102030
7
2
4
3
0

在线编程 IDE

建议全屏模式获得最佳体验