402919: GYM100947 G Square Spiral Search

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

Description

G. Square Spiral Searchtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard output

A new computer scientist is trying to develop a new memory management system called "spiral memory management".

The basic idea of this system is that it represents the memory as a 2D grid with a predefined origin point, and the address of each memory location is represented as its (x,y) coordinates, and it tries to store frequently used data as close to the origin point as possible.

This system needs a search algorithm. Our computer scientist is currently developing an algorithm called "square spiral search".

The algorithm searches the memory locations in the following order (also shown in the figure):

(0,0), (1,0), (1,1), (0,1), (-1,1), (-1,0), (-1,-1), (0,-1), (1,-1), (2,-1), (2,0), (2,1), (2,2), (1,2), (0,2), (-1,2), (-2,2), (-2,1), (-2,0), (-2,-1), (-2,-2,) ,(-1,-2) ... and so on.

Now he is wondering: how many steps would it take to reach a memory location with the address (x, y) using the square spiral search. Can you help him find the answer?

Input

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

Each test case consists of two numbers: X, Y the address of the memory location.

 - 1, 000, 000, 000 ≤ X ≤ 1, 000, 000, 000

 - 1, 000, 000, 000 ≤ Y ≤ 1, 000, 000, 000

Output

For each test case print the number of steps it would take to reach the memory location ( x, y ) .

ExamplesInput
3
1 0
1 1
-2 1
Output
1
2
17
Note

The number of steps to reach a memory location is defined as the number of memory locations searched before searching the requested location.

加入题单

算法标签: