Intelligent Robots
Time limit1sMemory limit128 MB
Decide whether a square robot moving only horizontally and vertically can leave the bounding rectangle of a rectilinear polygon without touching it.
Problem
We have a robot and an obstacle in a 2-dimensional plane. The robot is an axis-aligned (rectilinear) square, and the obstacle is a rectilinear polygon, meaning every edge is either horizontal or vertical. Initially the robot lies completely outside the obstacle: it does not touch the boundary and is not in the interior.
The robot wants to escape the obstacle by translating in horizontal or vertical directions without ever intersecting it. The robot has escaped once it lies completely outside the smallest axis-aligned rectangle that contains the obstacle (see Figure 1 and Figure 2). The robot may already start outside that rectangle.
In Figure 1 the robot cannot escape, but in Figure 2 it can. marks the robot and marks the obstacle. Let be a vertex of ; then and are both multiples of with . The side length of is a natural number below whose last digit is always (for example ).

Figure 1

Figure 2
Write a program that decides whether the robot can escape the obstacle.
Input
The first line contains the number of test cases .
Each test case is given as follows. The first line contains three integers , , and (), where is the bottom-left corner of the robot and is its side length, whose last digit is always . The second line contains an integer (), the number of vertices of the rectilinear polygon . Each of the next lines gives one vertex of in counterclockwise order as two integers and (, both multiples of ). In every test case the robot starts outside .
Output
For each test case, print YES on its own line if the robot can escape the obstacle, or NO otherwise.