409900: GYM103828 M Mobile Game

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

Description

M. Mobile Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Ali and Nour have decided to play a mobile game, the game will give an integer $$$x$$$ to Ali and an integer $$$y$$$ to Nour.

Each second, the game will print a number. It will print the numbers $$$1,$$$ $$$2,$$$ $$$3,$$$ $$$\dots$$$ in that order.

For each number, either Ali can take that number and subtract it from $$$x$$$ or Nour can take that number and subtract it from $$$y$$$.

The game ends when $$$x \le 0$$$ and $$$y \le 0$$$.

Since the battery of their device is running low, they want to finish the game as quickly as possible. Your task is to find the minimum number of seconds needed to finish the game.

Input

The first line of input contains a single integer $$$T$$$ $$$(1 \le T \le 10^5)$$$, the number of test cases.

The next $$$T$$$ lines each contain two space-separated integers $$$x$$$ and $$$y$$$ $$$(1 \le x, y \le 10^{18})$$$ - the numbers given to Ali and Nour by the game.

Output

Print $$$T$$$ lines, each containing a single integer, the minimum number of seconds needed to finish the game by making $$$x \le 0$$$ and $$$y \le 0$$$.

ExampleInput
2
4 7
6 4
Output
5
4
Note

Explanation of the sample:

In the first test case, Ali will take $$$1$$$, $$$2$$$, and $$$3$$$, then Nour will take $$$4$$$ and $$$5$$$, so they can finish the game in 5 seconds.

In the second test case, Nour will first take $$$1$$$, then Ali will take $$$2$$$, then Nour will take $$$3$$$, and finally, Ali will take $$$4$$$, so they can finish the game in 4 seconds.

加入题单

算法标签: