6680.Number Spiral

Time Limit: 1s Memory Limit: 512MB

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

1071-1.png

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

Input Format(From the terminal/stdin)

The first input line contains an integer $t$ : the number of tests.

After this, there are $t$ lines, each containing integers $y$ and $x$ .

  • $1 \le t \le 10^5$
  • $1 \le y,x \le 10^9$

Output Format(To the terminal/stdout)

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

Sample Input

Copy
3
2 3
1 1
4 2
 \n
 · \n
 · \n
 · \n

Sample Output

Copy
8
1
15
 \n
 \n
  \n
Source: CSES, Introductory Problems, 1071

Submit

请先 登录

© 2025 FAQs