Problem: Vladislav has cards numbered . He wants to lay them down in a row as follows:
- First, he lays down all the odd-numbered cards from smallest to largest.
- Next, he lays down all cards that are twice an odd number from smallest to largest (i.e. multiplied by an odd number).
- Next, he lays down all cards that are times an odd number from smallest to largest (i.e. multiplied by an odd number).
- Next, he lays down all cards that are times an odd number from smallest to largest (i.e. multiplied by an odd number).
- And so on, until all cards are laid down.
Input Format: The first line contains an integer () — the number of test cases.
The only line of each test case contains two integers and () — the number of cards Vlad has, and the position of the card you need to output.
Output Format: For each test case, output a single integer — the -th card Vladislav lays down.
Note: In the first seven test cases, . Vladislav lays down the cards as follows:
- First — all the odd-numbered cards in the order , , , .
- Next — all cards that are twice an odd number in the order , .
- Next, there are no remaining cards that are times an odd number. (Vladislav has only one of each card.)
- Next — all cards that are times an odd number, and there is only one such card: .
- There are no more cards left, so Vladislav stops.