Problem: on_the_run (2019 round2)

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).

They've tracked Mr. X down to a yard in Scotland, which may be represented as
a grid with **N** rows (numbered 1 to **N**) and **M** columns (numbered 1 to
**M**). Mr. X is initially in row **A** and column **B**. There are also **K**
(1 ≤ **K** ≤ 2) HAHA agents hot on his trail, the _i_th of whom is initially
in row **Ri** and column **Ci**. All **K**+1 individuals are in distinct
cells.

The chase will then commence in an organized fashion as follows:

  1. Each of the **K** 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. 
  2. 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. 

* _An unoccupied cell is one which currently contains neither Mr. X nor an agent._

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.

### Input

Input begins with an integer **T**, 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 **N**, **M**, and **K**. Then there is a line containing
the space-separated integers **A**, and **B**. Then, **K** lines follow, the
_i_th of which contains the space-separated integers **Ri** and **Ci**.

### Output

For the _i_th chase, print a line containing "Case #_i_: " followed by one
character, either "Y" if Mr. X will eventually be forced to surrender, or "N"
otherwise.

### Constraints

1 ≤ **T** ≤ 500  
3 ≤ **N**, **M** ≤ 300  
1 ≤ **K** ≤ 2  
1 ≤ **A**, **Ri** ≤ **N**  
1 ≤ **B**, **Ci** ≤ **M**  

### Explanation of Sample

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.

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.



Sample input:
8
3 3 1
1 1
2 2
3 3 2
1 1
1 3
3 1
4 4 2
1 2
1 3
1 4
3 10 2
2 10
1 9
3 9
8 8 2
8 1
8 8
1 1
300 5 2
2 3
15 2
300 5
67 25 2
32 10
66 3
21 18
71 87 2
36 44
1 87
71 1


Sample output:
Case #1: N
Case #2: Y
Case #3: N
Case #4: Y
Case #5: N
Case #6: Y
Case #7: N
Case #8: Y



Code: // On the Run
// Solution by Jacob Plachta

#define DEBUG 0

#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <sstream>
using namespace std;

#define LL long long
#define LD long double
#define PR pair<int,int>

#define Fox(i,n) for (i=0; i<n; i++)
#define Fox1(i,n) for (i=1; i<=n; i++)
#define FoxI(i,a,b) for (i=a; i<=b; i++)
#define FoxR(i,n) for (i=(n)-1; i>=0; i--)
#define FoxR1(i,n) for (i=n; i>0; i--)
#define FoxRI(i,a,b) for (i=b; i>=a; i--)
#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Min(a,b) a=min(a,b)
#define Max(a,b) a=max(a,b)
#define Sz(s) int((s).size())
#define All(s) (s).begin(),(s).end()
#define Fill(s,v) memset(s,v,sizeof(s))
#define pb push_back
#define mp make_pair
#define x first
#define y second

template<typename T> T Abs(T x) { return(x<0 ? -x : x); }
template<typename T> T Sqr(T x) { return(x*x); }
string plural(string s) { return(Sz(s) && s[Sz(s)-1]=='x' ? s+"en" : s+"s"); }

const int INF = (int)1e9;
const LD EPS = 1e-12;
const LD PI = acos(-1.0);

#if DEBUG
#define GETCHAR getchar
#else
#define GETCHAR getchar_unlocked
#endif

bool Read(int &x)
{
	char c,r=0,n=0;
	x=0;
		for(;;)
		{
			c=GETCHAR();
				if ((c<0) && (!r))
					return(0);
				if ((c=='-') && (!r))
					n=1;
				else
				if ((c>='0') && (c<='9'))
					x=x*10+c-'0',r=1;
				else
				if (r)
					break;
		}
		if (n)
			x=-x;
	return(1);
}

int main()
{
		if (DEBUG)
			freopen("in.txt","r",stdin);
	// vars
	int T,t;
	int N,M,K;
	int i,r,c;
	int P[3];
	// testcase loop
	Read(T);
		Fox1(t,T)
		{
			// input
			Read(N),Read(M),Read(K);
				Fox(i,K+1)
				{
					Read(r),Read(c);
					P[i]=(r+c)%2;
				}
			// output
			printf("Case #%d: %c\n",t,(K==2 && P[1]==P[0] && P[2]==P[0]) ? 'Y' : 'N');
		}
	return(0);
}