Even Digits
Vinn has a unique calculator that only has a display, a plus button, and a minus button. Currently, the integer N is displayed on the calculator's screen.
Pressing the plus button increases the current number displayed on the screen by \(1\), while pressing the minus button decreases it by \(1\). The calculator does not show leading zeros; for example, if 100 is displayed and the minus button is pressed once, the calculator will display 99.
Vinn does not like odd digits and wants to display an integer containing only even digits in its decimal representation, using only the calculator's buttons. Since the calculator is old and the buttons are hard to press, his goal is to use the minimum number of button presses.
Please help Vinn to determine the minimum number of button presses to make the calculator display an integer with no odd digits.
Input
The first line of the input indicates the number of test cases, T. T test cases follow. Each begins with a line containing an integer N: the number initially displayed on Vinn's calculator.
Output
For each test case, you must print one line containing y, where y is the minimum number of button presses required.
Limits
Small dataset (Test set 1 - Visible) \(1 \le N \le 10^5\).
Large dataset (Test set 2 - Hidden) \(1 \le N \le 10^{16}\).
Example
| Sample Input | Sample Output |
|---|---|
| 4 | |
| 42 | 0 |
| 11 | 3 |
| 1 | 1 |
| 2018 | 2 |
In Sample Case #1, the integer initially displayed has no odd digits, so no button presses are needed.
In Sample Case #2, pressing the minus button three times will cause the calculator to display 8, and there is no way to meet the requirements with fewer than three button presses.
In Sample Case #3, pressing the minus button once (displaying 0) or the plus button once, will cause the calculator to display an integer with no odd digits.
In Sample Case #4, pressing the plus button twice will cause the calculator to display 2020, making it impossible to achieve this with fewer than two button presses.
Comments