Park

Given non-overlapping tree circles in a rectangular park, decide for each visitor circle which corner entrances they can reach without overlapping any tree or the fence.

Medium7GeometryUnion-findGraphMathNo attempts yetTime limit2.5sMemory limit256 MB

Problem

In the capital of Byteland there is a rectangular park surrounded by a fence. The trees and the visitors in the park are all drawn as circles.

The park has one entrance in each corner. Entrance 1 is the bottom left corner, entrance 2 is the bottom right corner, entrance 3 is the top right corner, and entrance 4 is the top left corner. A visitor can enter and leave the park only through an entrance.

A visitor enters or leaves through an entrance when the visitor touches both sides of that corner at the same time. Inside the park a visitor moves freely, but a visitor must never overlap a tree or the fence. Touching is not overlapping, so touching is allowed.

Every visitor comes in through a given entrance. For each visitor, determine the entrances that visitor can leave through.

Input

The first line contains the number of trees in the park nn and the number of visitors mm.

The second line contains the width ww and the height hh of the park. The bottom left corner of the park is (0,0)(0, 0) and the top right corner is (w,h)(w, h).

Each of the next nn lines contains three integers xx, yy and rr describing a tree. The center of the tree is (x,y)(x, y) and its radius is rr. The trees do not overlap each other and they do not overlap the fence.

Each of the last mm lines contains two integers rr and cc describing a visitor. rr is the radius of the visitor and cc is the entrance that visitor comes in through.

Output

For each visitor print one line with the entrances that visitor can leave through, in increasing order and with no spaces in between. The entrance cc the visitor came in through is always part of the answer.

Constraints

  • 0n10000 \le n \le 1000
  • 1m1000001 \le m \le 100000
  • 4k<w1094k < w \le 10^9 and 4k<h1094k < h \le 10^9, where kk is the radius of the largest visitor.
  • The radius of a tree satisfies 1r1091 \le r \le 10^9.
  • The radius of a visitor satisfies 1r1091 \le r \le 10^9 and the entrance number satisfies 1c41 \le c \le 4.
  • Every number in the input is an integer.

Notes

Two shapes touch if they have exactly one common point, and they overlap if they have two or more common points. So if the gap between two trees is exactly as wide as the diameter of a visitor, that visitor can pass between them while touching both. The same holds for a gap between a tree and the fence.

The figure below shows the entrance areas and the routes each visitor of the first example can take.