Under construction

Still being built. Things may change

Kitchen Timer

Interview

Time limit2sMemory limit1024 MB

Summary
Split x into the fewest terms of the form 2^k - 1 (k at least 1) and output the number of terms minus one.
Level

Medium5 of 10

Topics
Greedy, Math, Bit manipulation
Solved
No attempts yet

Problem

Kenny has a microwave in his kitchen. Its timer uses a single button with an unusual interface. You press the button one or more times to start heating. The first press sets the timer to 11 minute. If you press again immediately, 22 minutes are added, for a total of 33 minutes. Another immediate press adds 44 more minutes, and so on. If you press the button for the kk-th time without a pause, it adds 2k2^k minutes to the timer.

It seems impossible to set some amounts of time with the button. For example, how do you set the timer for 22 minutes? You can reset the press counter by pausing for one second. If you press, pause for one second, and then press again, the timer is set to 22 minutes. Another example: if you press, press, pause, press, press, press, the total time is 1+2+1+2+4=101+2+1+2+4=10 minutes.

Kenny needs to heat his food for exactly xx minutes. Find the minimum number of one-second pauses he needs to set the timer. Only pauses take time. The time spent pressing the button is ignored.

Input

The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). Each of the next tt lines contains a single integer xx (1≤x≤10181 \le x \le 10^{18}), the number of minutes Kenny needs to heat his food.

Output

For each test case, print the minimum number of one-second pauses needed to set the timer to xx minutes, one answer per line.

Hint

In the first test case, no pauses are needed. Kenny can press the button once.

In the second test case, Kenny can press, pause, press to set the timer to 22 minutes.

In the third test case, Kenny can press the button twice to set the timer to 33 minutes.

In the fourth test case, Kenny can press, press, pause, press to set the timer to 1+2+1=41 + 2 + 1 = 4 minutes.

Examples1

  1. Example 1

    Input
    7
    1
    2
    3
    4
    10
    239
    123456789012
    
    Expected output
    0
    1
    0
    1
    1
    4
    19