Broken Calculator
Time limit2sMemory limit1024 MB
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.
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 to the number on the screen, subtract , multiply by , or divide by . The decimal point function also broke, so a number that is not divisible by cannot be divided by . 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 , find the minimum number of button clicks needed to display . The screen starts at .
Input
The first line contains the number of test cases . ()
Each test case gives an integer to produce. ()
Output
For each test case, print the minimum number of button clicks needed to produce .