Технокубок 2021 - Финал
A
Prison Break
Codeforces
800
原题
←B →
翻译中…

Michael is accused of violating the social distancing rules and creating a risk of spreading coronavirus. He is now sent to prison. Luckily, Michael knows exactly what the prison looks like from the inside, especially since it's very simple.

翻译中…

The prison can be represented as a rectangle $a\times b$ which is divided into $ab$ cells, each representing a prison cell, common sides being the walls between cells, and sides on the perimeter being the walls leading to freedom. Before sentencing, Michael can ask his friends among the prison employees to make (very well hidden) holes in some of the walls (including walls between cells and the outermost walls). Michael wants to be able to get out of the prison after this, no matter which cell he is placed in. However, he also wants to break as few walls as possible.

翻译中…

Your task is to find out the smallest number of walls to be broken so that there is a path to the outside from every cell after this.

翻译中…

Input

翻译中…

The first line contains a single integer $t$ ($1\leq t\leq 100$) — the number of test cases.

翻译中…

Each of the following $t$ lines contains two integers $a$ and $b$ ($1\leq a, b\leq 100$), representing a corresponding test case.

翻译中…

Output

翻译中…

For each test case print the single integer on a separate line — the answer to the problem.

翻译中…

Note

翻译中…

Some possible escape plans for the example test cases are shown below. Broken walls are shown in gray, not broken walls are shown in black.

翻译中…

image

翻译中…

image

翻译中…

样例

Input #1
2
2 2
1 3
Output #1
4
3
InputCopy OutputCopy
题目信息
题号
1482A
时间限制
1 s
内存限制
256 MB
标签
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。