CF2149F Nezuko in the Clearing

Description

Nezuko suddenly woke up on the number line at point $ 0 $ and has $ h $ health points. She wants to reach point $ d $ . In one turn, she can do exactly one of two things: - rest in the shade and increase her current health by $ 1 $ ; - move from her current position $ x $ to $ x + 1 $ . Each movement decreases Nezuko's health; if the movement is the $ j $ -th consecutive movement, her health will decrease by $ j $ points. If as a result of a move Nezuko's health drops to $ 0 $ or below, she cannot make that move. For example, if Nezuko initially had $ 7 $ health points and $ d=4 $ , her moves could look like this: 1. Move from $ 0 $ to $ 1 $ and decrease health by $ 1 $ . Now she is at point $ 1 $ with $ 6 $ health points. 2. Move from $ 1 $ to $ 2 $ and decrease health by $ 2 $ . Now she is at point $ 2 $ with $ 4 $ health points. 3. Move from $ 2 $ to $ 3 $ and decrease health by $ 3 $ . Now she is at point $ 3 $ with $ 1 $ health point. 4. Rest and restore $ 1 $ health point. Now she is at point $ 3 $ with $ 2 $ health points. 5. Move from $ 3 $ to $ 4 $ and decrease health by $ 1 $ . Now she is at point $ 4 $ with $ 1 $ health point. Find the minimum number of turns required for her to reach point $ d $ .

Input Format

Each test consists of several test cases. The first line contains one integer $ t $ ( $ 1 \le t \le 10^4 $ ) — the number of test cases. The following describes the test cases. The first line of each test case contains two integers $ h $ and $ d $ $ (1\le h,d \le 10^9) $ — the number of health points and the destination point, respectively.

Output Format

For each test case, output one number — the minimum number of turns required for Nezuko to reach point $ d $ .

Explanation/Hint

In the first test case, $ h = 3 $ , $ d = 2 $ the actions could be as follows: 1. Move from $ 0 $ to $ 1 $ and decrease health by $ 1 $ . Now she is at point $ 1 $ with $ 2 $ health points. 2. Rest and restore $ 1 $ health point. Now she is at point $ 1 $ with $ 3 $ health points. 3. Move from $ 1 $ to $ 2 $ and decrease health by $ 1 $ . Now she is at point $ 2 $ with $ 2 $ health points. In total, $ 3 $ turns. In the fourth test case, $ h = 2 $ , $ d = 4 $ the actions could be as follows: 1. Move from $ 0 $ to $ 1 $ and decrease health by $ 1 $ . Now she is at point $ 1 $ with $ 1 $ health point. 2. Rest and restore $ 1 $ health point. Now she is at point $ 1 $ with $ 2 $ health points. 3. Move from $ 1 $ to $ 2 $ and decrease health by $ 1 $ . Now she is at point $ 2 $ with $ 1 $ health point. 4. Rest and restore $ 1 $ health point. Now she is at point $ 2 $ with $ 2 $ health points. 5. Move from $ 2 $ to $ 3 $ and decrease health by $ 1 $ . Now she is at point $ 3 $ with $ 1 $ health point. 6. Rest and restore $ 1 $ health point. Now she is at point $ 3 $ with $ 2 $ health points. 7. Move from $ 3 $ to $ 4 $ and decrease health by $ 1 $ . Now she is at point $ 4 $ with $ 1 $ health point. In total, $ 7 $ turns.