HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Unsorted > problem:


Number Spiral

Section problems

• Missing Number
• Increasing Array
• Coin Piles
• Josephus Queries
• Apartments
• Apple Division
• Creating Strings
• Trailing Zeros
• Number Spiral
• Two Sets
• Maximum Subarray Sum
• Ferris Wheel
• Distinct Numbers
• Dice Combinations
• Finding Periods
• Finding Borders
• Minimal Rotation

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 3000/5000/5000/5000 ms. Memory limit 65000/65000/65000/65000 Kb. Difficulty Beta


A number spiral is an infinite grid whose upper-left square has number 1.
Here are the first five layers of the spiral:



Your task is to find out the number in row y and column x.

Input
The first input line contains an integer t: the number of tests.
After this, there are t lines, each containing integers y and x.

Output
For each test, print the number in row y and column x.

Constraints
1≤t≤105
1≤y,x≤109

Example
Input:
3
2 3
1 1
4 2
Output:
8
1
15

Для отправки решений необходимо выполнить вход.

www.contester.ru