A. Crossmarket
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Stanley and Megan decided to shop in the "Crossmarket" grocery store, which can be represented as a matrix with $n$ rows and $m$ columns.

Stanley and Megan can move to an adjacent cell using $1$ unit of power. Two cells are considered adjacent if they share an edge. To speed up the shopping process, Megan brought her portals with her, and she leaves one in each cell she visits (if there is no portal yet). If a person (Stanley or Megan) is in a cell with a portal, that person can use $1$ unit of power to teleport to any other cell with a portal, including Megan's starting cell.

They decided to split up: Stanley will go from the upper-left cell (cell with coordinates $(1, 1)$) to the lower-right cell (cell with coordinates $(n, m)$), whilst Megan needs to get from the lower-left cell (cell with coordinates $(n, 1)$) to the upper-right cell (cell with coordinates $(1, m)$).

What is the minimum total energy needed for them both to do that?

Note that they can choose the time they move. Time does not affect energy.

Input

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). Description of the test cases follows.

The only line in the test case contains two integers $n$ and $m$ ($1 \le n, m \le 10^5$).

Output

For each test case print a single integer on a new line – the answer.

Example
Input
77 55 71 1100000 10000057 2281 55 1
Output
15
15
0
299998
340
5
5

Note In the first test case they can stick to the following plan:

1. Megan (red circle) moves to the cell $(7, 3)$. Then she goes to the cell $(1, 3)$, and Stanley (blue circle) does the same.
2. Stanley uses the portal in that cell (cells with portals are grey) to get to the cell $(7, 3)$. Then he moves to his destination — cell $(7, 5)$.
3. Megan also finishes her route and goes to the cell $(1, 5)$.

The total energy spent is $(2 + 6) + (2 + 1 + 2) + (2)= 15$, which is our final answer.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8638319,"math_prob":0.9862829,"size":1649,"snap":"2023-14-2023-23","text_gpt3_token_len":441,"char_repetition_ratio":0.12218845,"word_repetition_ratio":0.013422819,"special_character_ratio":0.3274712,"punctuation_ratio":0.09063444,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9797913,"pos_list":[0,1,2],"im_url_duplicate_count":[null,1,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-05-30T20:27:12Z\",\"WARC-Record-ID\":\"<urn:uuid:6b8cbe36-f91a-47da-9a71-34c5723463c5>\",\"Content-Length\":\"59385\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:db637963-8d02-4f0f-8a65-cca5a1844f18>\",\"WARC-Concurrent-To\":\"<urn:uuid:c6675632-b1d8-475a-acfc-0698cdae7fa2>\",\"WARC-IP-Address\":\"172.67.68.254\",\"WARC-Target-URI\":\"https://codeforces.com/problemset/problem/1715/A\",\"WARC-Payload-Digest\":\"sha1:WRMZSXTRZQWGOFTG5V7IW4UUVBY6XFV4\",\"WARC-Block-Digest\":\"sha1:OTCTJTQGVXLKKSRXYHYFKMLR2LF5VWMY\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224646144.69_warc_CC-MAIN-20230530194919-20230530224919-00289.warc.gz\"}"}