Limits 1s, 256 MB

Given NN. You can perform 3 types of operations:

  1. Increase NN by 1.
  2. Decrease NN by 1.
  3. Divide NN by 2, available only when NN is even.

You have to find the minimum number of operations needed to reach 1.

Input

The first line of the input will contain an integer TT (1T1061 \le T \le 10^6), the number of test cases. Each of the next T lines will contain an integer NN (1N1061 \le N \le 10^6), as described in the problem statement.

Output

For each test case, you have to find the minimum number of operations needed to reach 1.

Sample

InputOutput
5
2
3
4
5
23
1
2
2
3
6

Submit

Login to submit.

Contributors

Statistics

86% Solution Ratio
qwerty321Earliest, Jan '20
JIANEEFastest, 0.0s
JIANEELightest, 5.5 kB
GameLordShortest, 259B
Toph uses cookies. By continuing you agree to our Cookie Policy.