CF2122A.Greedy Grid

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Greedy Grid

A path in a grid is called greedy if it starts at the top-left cell and moves only to the right or downward, always moving to its neighbor with the greater value (or either if the values are equal).

The value of a path is the sum of the values of the cells it visits, including the start and end.

Does there exist an n×mn \times m grid of nonnegative integers such that no greedy path achieves the maximum value among all down/right paths?

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t50001 \le t \le 5000). The description of the test cases follows.

The only line of each test case contains two integers nn, mm (1n,m1001 \leq n, m \leq 100) — the number of rows and columns in the grid, respectively.

Output

For each test case, on a separate line output "YES" if the required grid exists, and "NO" otherwise.

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

Note

In the first test case, an example of a grid in which no greedy path achieves the maximum value out of all down/right paths is: $$ \begin{bmatrix} 3 & 5 & 1 \ 2 & 1 & 2 \ 5 & 4 & 3 \ \end{bmatrix}$$Leta_i,ja\_{i, j}denote the value of the cell in theii-th row andjj-th column. The maximum value of a down/right path is$a\_{1,1} + a\_{2,1} + a\_{3,1} + a\_{3,2} + a\_{3,3} = 17$. This path isn't greedy becausea_1,2a\_{1,2}is greater thana_2,1a\_{2,1}; thus, a greedy path must move right in the first step. The maximum value of a greedy path is$a\_{1,1} + a\_{1,2} + a\_{2,2} + a\_{3,2} + a\_{3,3} = 16$.

In the second test case, it can be proven that no grid satisfies the conditions.

Samples

2
3 3
1 2
YES
NO

在线编程 IDE

建议全屏模式获得最佳体验