Under construction

Still being built. Things may change

RFID Tracking

Time limit3sMemory limit128 MB

Summary
Given sensors, walls, and items on a plane, find for each item all sensors whose distance minus the number of walls crossed is within range r, then print them sorted by coordinates.
Level

Medium6 of 10

Topics
Geometry, Simulation, Brute force
Solved
No attempts yet

Problem

Sunyoung runs a warehouse. When a customer places an order, she finds the item in the warehouse, packs it into a box, and ships it.

Every item stored in the warehouse has a single RFID chip attached to it. Sensors are mounted on the ceiling of the warehouse to track the positions of the items.

Each sensor has a range of rr. That is, a sensor can locate any chip whose straight-line distance from the sensor is at most rr. However, if the line segment connecting a sensor and an item crosses or touches walls, the sensor's range is reduced by the number of walls it crosses or touches. In other words, for a given item the sensor's effective range equals rr minus the number of walls that the segment between the sensor and the item crosses or touches, and the sensor can read the chip only when the straight-line distance between the sensor and the item is at most this effective range.

Also, because sensors placed too close together cause interference, the distance between every pair of sensors is at least rr. No sensor or item ever lies on a wall.

For each item, write a program that finds all sensors that can read that item's RFID chip.

Input

The first line contains the number of test cases, which is at most 100.

The first line of each test case contains the number of sensors ss, the sensor range rr, the number of walls ww, and the number of items pp. (1≤s≤2500001 \le s \le 250000, 1≤r≤201 \le r \le 20, 0≤w≤100 \le w \le 10, 1≤p≤100001 \le p \le 10000)

The next ss lines each contain the coordinates xix_i, yiy_i of a sensor. The distance between every pair of sensors is at least rr. (−10000≤xi,yi≤10000-10000 \le x_i, y_i \le 10000)

The next ww lines each contain four integers bxibx_i, byiby_i, exiex_i, eyiey_i. (−10000≤bxi,byi,exi,eyi≤10000-10000 \le bx_i, by_i, ex_i, ey_i \le 10000) Each wall is the line segment joining (bxi,byi)(bx_i, by_i) and (exi,eyi)(ex_i, ey_i), and its length is positive.

The last pp lines each contain the coordinates pxipx_i, pyipy_i of an item. (−10000≤pxi,pyi≤10000-10000 \le px_i, py_i \le 10000)

Output

For each test case, for each item output the number of sensors that can detect it, followed by the coordinates of those sensors. If there are multiple sensors, print them in increasing order of xx coordinate, breaking ties by increasing yy coordinate. Write each sensor's coordinates in the form (x,y), and separate the count and each coordinate by a single space. If no sensor can detect the item, print only 0.

Examples5

  1. Example 1

    Input
    1
    4 3 4 7
    0 0
    -1 3
    2 3
    11 5
    -4 -1 5 -1
    3 4 6 1
    11 4 11 3
    12 5 12 8
    1 1
    0 -2
    4 4
    11 2
    13 5
    13 7
    14 5
    
    Expected output
    3 (-1,3) (0,0) (2,3)
    1 (0,0)
    0
    0
    1 (11,5)
    0
    0
    
  2. Example 2

    Input
    1
    3 5 0 3
    0 0
    10 0
    0 10
    3 4
    7 0
    5 5
    
    Expected output
    1 (0,0)
    1 (10,0)
    0
    
  3. Example 3

    Input
    1
    3 5 0 1
    0 3
    0 -3
    5 0
    2 0
    
    Expected output
    3 (0,-3) (0,3) (5,0)
    
  4. Example 4

    Input
    1
    1 4 1 3
    0 0
    2 0 2 3
    4 0
    3 0
    5 0
    
    Expected output
    0
    1 (0,0)
    0
    
  5. Example 5

    Input
    1
    1 5 1 2
    0 0
    0 2 0 3
    0 5
    0 4
    
    Expected output
    0
    1 (0,0)