#T2006. 数字螺旋(Number Spiral)

数字螺旋(Number Spiral)

链接: https://cses.fi/problemset/task/1071

板块: Introductory Problems

时限: 1.00 s | 内存: 512 MB

题目描述

数字螺旋是一个无限大的网格,其左上角的格子数字为 1。(图示见原页:https://cses.fi/file/bba36f2601b99c7edc15865aa2a49e680a271075f30e86aa0e4e18d00a779c21) 你的任务是求出第 yy 行、第 xx 列格子中的数字。

输入描述

第一行输入包含一个整数 tt:测试用例的数量。 随后有 tt 行,每行包含两个整数 yyxx

输出描述

对于每个测试用例,打印第 yy 行、第 xx 列格子中的数字。

数据范围

1t1051 \le t \le 10^5

1y,x1091 \le y,x \le 10^9

样例输入

3
2 3
1 1
4 2

样例输出

8
1
15