403199: GYM101064 F Metal detector

Memory Limit:256 MB Time Limit:0 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Metal detectortime limit per test0.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Since the 2017 world finals will be in Rapid City, South Dakota, the MaratonIME's coach decides to visit the city to know the contest location.

The city is preparing to receive the best computer programmers in the world. To ensure the safety of the event, metal detectors are being installed at the entrance of the convention center where the contest will be held. To avoid long waits in the line, the security officers were instructed to send every person that activates the metal detector to the end of the line.

The coach noticed that one of the metal detectors is defective and it is always activated alternately. This means that the first person does not activate it and the next person does. The third person does not activate it and the next person does, and so on.

Given that there are N people in the line, the coach, that is the i-th in the line, wants to know when he will be able to go through the metal detector without activating it.

Input

The input starts with an integer T, the number of test cases.

Each test case consists of two integers, N and i, corresponding to the number of people in the line and the position of the coach in the line, respectively.

Limits

  • 1 ≤ T ≤ 103
  • 1 ≤ N ≤ 109
  • 1 ≤ i ≤ N
Output

For each test case, print a line with one integer j meaning that the coach will be the j-th person to go through the metal detector without activating it.

ExampleInput
2
5 1
6 2
Output
1
4

Source/Category

加入题单

算法标签: