


The position of the robot can be negative.
The first line contains a single integer ‘T’ representing the number of test cases. The 'T' test cases follow.
The first line of each test case will contain a single integer ‘TARGET’.
For each test case, print an integer representing the length of the shortest sequence of instruction to reach position equals ‘TARGET’.
Output for every test case will be printed in a separate line.
You don’t need to print anything, It has already been taken care of. Just implement the given function.
1 <= 'T' <= 50
1 <= ‘TARGET’ <= 10000
Time limit: 1 sec
The basic idea is to use modified Breadth-First Search (BFS) here. We can keep track of all the possible positions of the robot after ‘N’ instructions (N = 0, 1, 2, 3, 4, ...) and return the smallest ‘N’ such that the ‘TARGET’ position is reached
The steps are as follows:
Let ‘N’ be the number of bits in the binary representation of ‘TARGET’, Then if ‘TARGET’ = 2^N -1, then the shortest sequence will consist of ‘N’ “A”s,
Otherwise, there are two possible ways to reach the target -:
1. To pass out the target and then reverse direction -: Robot first follow the sequence of ‘N’ “A”s and then one ‘R’ to reverse direction, after that, we need to find the shortest sequence length required to reach 2^N-1-’TARGET’, Let ‘M’ be this length, then answer will be N + 1 + M.
2. To go as far as possible before pass ‘TARGET’ then reverse back and again start to move in direction of ‘TARGET’ -: We give robot ‘N-1’ instruction of ‘A’ than one ‘R’ then some ‘K’ instruction of ‘A’ such that K < N.
The steps are as follows: