This page is still under construction.

Parts of this page are still being built. What you see may change.

Intelligent Robots

Time limit1sMemory limit128 MB

Summary
Decide whether a square robot moving only horizontally and vertically can leave the bounding rectangle of a rectilinear polygon without touching it.
Level

Hard8 of 10

Topics
Geometry, Graph, BFS
Solved
No attempts yet

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. RR marks the robot and PP marks the obstacle. Let (x,y)(x, y) be a vertex of PP; then xx and yy are both multiples of 1010 with 10≤x,y≤1,000,00010 \le x, y \le 1{,}000{,}000. The side length of RR is a natural number below 1,000,0001{,}000{,}000 whose last digit is always 22 (for example 2,12,22,32,…2, 12, 22, 32, \dots).

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

Each test case is given as follows. The first line contains three integers nxn_x, nyn_y, and ww (2≤nx,ny,w≤1,000,0002 \le n_x, n_y, w \le 1{,}000{,}000), where (nx,ny)(n_x, n_y) is the bottom-left corner of the robot RR and ww is its side length, whose last digit is always 22. The second line contains an integer nn (4≤n≤1,0004 \le n \le 1{,}000), the number of vertices of the rectilinear polygon PP. Each of the next nn lines gives one vertex of PP in counterclockwise order as two integers xx and yy (10≤x,y≤1,000,00010 \le x, y \le 1{,}000{,}000, both multiples of 1010). In every test case the robot starts outside PP.

Output

For each test case, print YES on its own line if the robot can escape the obstacle, or NO otherwise.

Examples3

  1. Example 1

    Input
    2
    30 30 12
    12
    10 10
    90 10
    90 60
    80 60
    80 20
    20 20
    20 70
    50 70
    50 50
    70 50
    70 90
    10 90
    200 200 52
    12
    450 500
    100 500
    100 100
    450 100
    450 250
    350 250
    350 150
    150 150
    150 300
    250 300
    250 400
    450 400
    
    Expected output
    NO
    YES
    
  2. Example 2

    Input
    1
    10 10 12
    4
    50 50
    150 50
    150 150
    50 150
    
    Expected output
    YES
    
  3. Example 3

    Input
    1
    40 40 12
    12
    10 10
    130 10
    130 130
    80 130
    80 90
    110 90
    110 30
    30 30
    30 90
    60 90
    60 130
    10 130
    
    Expected output
    YES