## WC '01 P3 - Back to the Future

View as PDF

Points: 5
Time limit: 1.0s
Memory limit: 16M

Problem type
##### Woburn Challenge 2001

P constructs the time machine outlined in Act I and has traveled back in time to this question (Act I is problem ). However, there is a slight problem in the programming. The machine works in binary, but by a LIFO (last-in, first-out) queue for all numbers that it processes. Therefore, when you type in a number (in base ) corresponding to the time period you wish to travel to, it converts it to binary (like all computers) but then reads it in LIFO order. Therefore, the last binary digit in the binary representation of the time period (ie. the leftmost digit) is the first one read and the first digit (the rightmost one) is the last one read.

The net result is that to compensate for P's inadequate programming skills, you need to do the following: If you wish to go to time period  , you need to convert to binary, reverse the bit order and then convert back to base . This final number is the one that you will actually enter into the computer. Making this calculation is your task.

#### Input Specification

The first line of the input contains , the number of test cases.
The remaining lines of the input each contain a number to be converted (in its original base format).

#### Output Specification

For each input, output the final number in base (i.e. with reversed bit order) on a separate line.

#### Sample Input

3
64
0
897112

#### Sample Output

1
0
106715