Under construction

Still being built. Things may change

Broken Calculator

Time limit2sMemory limit1024 MB

Summary
Given N, find the fewest clicks of +4, -4, *4, or /4 (division only when the number is divisible by 4) needed to reach N from 0.
Level

Medium7 of 10

Topics
Math, Greedy, Recursion
Solved
No attempts yet

Problem

Chanwoo, shaken after yet another stream of Wrong Answer verdicts, accidentally swung a shotgun at his beloved calculator. Most of the buttons broke from the impact. The only buttons still working add 44 to the number on the screen, subtract 44, multiply by 44, or divide by 44. The decimal point function also broke, so a number that is not divisible by 44 cannot be divided by 44. Fortunately, the screen still displays negative numbers correctly.

Unwilling to give up the calculator, Chanwoo decided to keep using it. He wondered about the fewest button clicks needed to show a given integer on the screen. Given NN, find the minimum number of button clicks needed to display NN. The screen starts at 00.

Input

The first line contains the number of test cases TT. (1≤T≤10 0001\leq T \leq 10\ 000)

Each test case gives an integer NN to produce. (0≤N≤10180\leq N \leq 10^{18})

Output

For each test case, print the minimum number of button clicks needed to produce NN.

Examples1

  1. Example 1

    Input
    5
    0
    17
    63
    128
    1234567890
    
    Expected output
    0
    5
    6
    4
    32