| <p> | |
| The world's funniest schoolteacher has found himself in some trouble. Or, should we say, the world's funniest ex-schoolteacher. | |
| On the basis of a false accusation regarding too many puns in his exam problems, Mr. X has not only been fired, but is now on the run from the Humane Association for Humour Administration (HAHA). | |
| </p> | |
| <p> | |
| They've tracked Mr. X down to a yard in Scotland, which may be represented as a grid with <strong>N</strong> rows (numbered 1 to <strong>N</strong>) | |
| and <strong>M</strong> columns (numbered 1 to <strong>M</strong>). Mr. X is initially in row <strong>A</strong> and column <strong>B</strong>. | |
| There are also <strong>K</strong> (1 ≤ <strong>K</strong> ≤ 2) HAHA agents hot on his trail, | |
| the <em>i</em>th of whom is initially in row <strong>R<sub>i</sub></strong> and column <strong>C<sub>i</sub></strong>. All <strong>K</strong>+1 individuals are in distinct cells. | |
| </p> | |
| <p> | |
| The chase will then commence in an organized fashion as follows: | |
| </p> | |
| <ol> | |
| <li> | |
| Each of the <strong>K</strong> HAHA agents in turn will move up, down, left, or right to an adjacent unoccupied cell* (without leaving the yard). | |
| The agents may choose to move in any order, but each of them must move exactly once, and multiple of them may not move simultaneously. | |
| It's guaranteed that all of the agents will always be able to move in some order for any possible state of the yard. | |
| </li> | |
| <li> | |
| Mr. X will then attempt to similarly move to an adjacent unoccupied cell. If he's unable to move due to there being no unoccupied cells adjacent to him, he'll surrender quietly instead. | |
| Otherwise, the process will repeat from Step 1. | |
| </li> | |
| </ol> | |
| <p> | |
| * <em>An unoccupied cell is one which currently contains neither Mr. X nor an agent.</em> | |
| </p> | |
| <p> | |
| Mr. X is hoping that, if he can avoid ever being forced to surrender, the HAHA agents may eventually leave him alone, | |
| giving him the opportunity to slip away and work on regaining his teaching position. | |
| However, the outcome of this chase seems difficult to call. Assuming that the agents work together optimally in an attempt to force Mr. X to surrender, while Mr. X optimally chooses moves to avoid surrendering indefinitely, determine whether or not he will eventually be forced to surrender. | |
| </p> | |
| <h3>Input</h3> | |
| <p> | |
| Input begins with an integer <strong>T</strong>, the number of times that Mr. X is chased by HAHA agents. | |
| For each chase, there is first a line containing the space-separated integers <strong>N</strong>, <strong>M</strong>, and <strong>K</strong>. | |
| Then there is a line containing the space-separated integers <strong>A</strong>, and <strong>B</strong>. | |
| Then, <strong>K</strong> lines follow, the <em>i</em>th of which contains the space-separated integers | |
| <strong>R<sub>i</sub></strong> and <strong>C<sub>i</sub></strong>. | |
| </p> | |
| <h3>Output</h3> | |
| <p> | |
| For the <em>i</em>th chase, print a line containing "Case #<em>i</em>: " | |
| followed by one character, either "Y" if Mr. X will eventually be forced to surrender, or "N" otherwise. | |
| </p> | |
| <h3>Constraints</h3> | |
| <p> | |
| 1 ≤ <strong>T</strong> ≤ 500 <br /> | |
| 3 ≤ <strong>N</strong>, <strong>M</strong> ≤ 300 <br /> | |
| 1 ≤ <strong>K</strong> ≤ 2 <br /> | |
| 1 ≤ <strong>A</strong>, <strong>R<sub>i</sub></strong> ≤ <strong>N</strong> <br /> | |
| 1 ≤ <strong>B</strong>, <strong>C<sub>i</sub></strong> ≤ <strong>M</strong> <br /> | |
| </p> | |
| <h3>Explanation of Sample</h3> | |
| <p> | |
| In the first case, no matter how much time goes by and what moves the HAHA agent chooses to make, Mr. X can always avoid needing to surrender. | |
| </p> | |
| <p> | |
| In the second case, if the first HAHA agent initially moves to cell (1, 2) and the second agent moves to cell (2, 1), then Mr. X will immediately be forced to surrender. | |
| </p> | |