Codeforces Round 915 (Div. 2)
A
Constructive Problems
Codeforces
800
原题
←B →
翻译中…

Gridlandia has been hit by flooding and now has to reconstruct all of it's cities. Gridlandia can be described by an $n \times m$ matrix.

翻译中…

Initially, all of its cities are in economic collapse. The government can choose to rebuild certain cities. Additionally, any collapsed city which has at least one vertically neighboring rebuilt city and at least one horizontally neighboring rebuilt city can ask for aid from them and become rebuilt without help from the government. More formally, collapsed city positioned in $(i, j)$ can become rebuilt if both of the following conditions are satisfied:

翻译中…
  • At least one of cities with positions $(i + 1, j)$ and $(i - 1, j)$ is rebuilt;
  • At least one of cities with positions $(i, j + 1)$ and $(i, j - 1)$ is rebuilt.
翻译中…

If the city is located on the border of the matrix and has only one horizontally or vertically neighbouring city, then we consider only that city.

翻译中…

image Illustration of two possible ways cities can be rebuilt by adjacent aid. White cells are collapsed cities, yellow cells are initially rebuilt cities (either by the government or adjacent aid), and orange cells are rebuilt cities after adjacent aid.

翻译中…

The government wants to know the minimum number of cities it has to rebuild such that after some time all the cities can be rebuild.

翻译中…

Input

翻译中…

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of the test cases follows.

翻译中…

The only line of each test case contains two integers $n$ and $m$ ($2 \le n, m \le 100$) — the sizes of Gridlandia.

翻译中…

Output

翻译中…

For each test case, output a single integer — the minimum number of cities the government needs to rebuild.

翻译中…

Note

翻译中…

In the first test case, it's enough for the government to rebuild cities $(1, 2)$ and $(2, 1)$.

翻译中…

In the second test case, it's enough for the government to rebuild cities $(1, 4)$, $(2, 2)$, $(3, 1)$, $(3, 6)$, $(4, 3)$, $(5, 5)$, $(5, 7)$.

翻译中…

样例

Input #1
3
2 2
5 7
3 2
Output #1
2
7
3
InputCopy OutputCopy
题目信息
题号
1905A
时间限制
1 s
内存限制
256 MB
标签
构造
数学

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