Technocup 2022 - Elimination Round 2
B
Coloring Rectangles
Codeforces
1000
原题
← AC →
翻译中…

David was given a red checkered rectangle of size $n \times m$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.

翻译中…

As a result, he will get a set of rectangles. Rectangles $1 \times 1$ are forbidden.

翻译中…

David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.

翻译中…

What is the minimum number of cells David will have to paint?

翻译中…

Input

翻译中…

The first line contains a single integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases. The next lines contain descriptions of test cases.

翻译中…

The only line of each test case contains two integers $n$, $m$ ($1 \leq n, m \leq 3 \cdot 10^4$, $n \cdot m \geq 2$).

翻译中…

Output

翻译中…

For each test case print a single integer — the minimum number of cells David will have to paint blue.

翻译中…

Note

翻译中…

The following pictures show how the initial rectangle can be split and cells colored blue.

翻译中…

In the first test case:

翻译中…

image

翻译中…

In the second test case:

翻译中…

image

翻译中…

In the third test case:

翻译中…

image

翻译中…

In the fourth test case:

翻译中…

image

翻译中…

样例

Input #1
4
1 3
2 2
2 5
3 5
Output #1
1
2
4
5
InputCopy OutputCopy
题目信息
题号
1584B
时间限制
1 s
内存限制
256 MB
标签
贪心
数学

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