Problem A

Statement
Copy Copied
A. Greedy Gridtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA 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 \times m$$$ grid of nonnegative integers such that no greedy path achieves the maximum value among all down/right paths?InputEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). The description of the test cases follows.  The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 100$$$) — the number of rows and columns in the grid, respectively.OutputFor 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.ExampleInput23 31 2OutputYES
NO
NoteIn 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} $$$$$$ Let $$$a_{i, j}$$$ denote the value of the cell in the $$$i$$$-th row and $$$j$$$-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 because $$$a_{1,2}$$$ is greater than $$$a_{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.