Given N disjoint ceiling segments, trace each vertically rising balloon as it sticks to horizontal segments or slides to the higher endpoint of tilted ones, and report the final resting point or escape x coordinate.
Hard8GeometrySortingBinary searchSimulationNo attempts yetTime limit2sMemory limit512 MBAfter a programming contest, the balloons that come loose and float up to the ceiling of the hall have to be collected. The contract with the owner of the hall requires the hall to be cleaned right after the event, and a fine applies otherwise. This year the organizers obtained the design drawing of the ceiling in advance. They want to know, for a balloon released at a given point of the floor, whether the ceiling blocks it and where it stops, or whether it escapes out of the hall.
Seen from the side, the ceiling is N line segments. No two of these segments have a point in common.
A balloon is a point. It is released on the floor at (X,0) and rises straight up. What happens next depends on the first segment it touches. The endpoints of a segment belong to that segment, so a balloon that rises exactly into an endpoint touches it.
The figure below shows one ceiling. The four marked points of the floor, a, b, c and d, are at x=2, x=5, x=6 and x=8.

For that ceiling, the balloons released at a and at b both get stuck at (2,5), the balloon released at c gets stuck at (6,5), and the balloon released at d is not blocked and escapes out of the hall at x=7.
Read the description of the ceiling and answer C queries about the final position of balloons released on the floor.
The first line contains two integers N and C, the number of segments that describe the ceiling and the number of queries.
Each of the next N lines contains four integers X1, Y1, X2, Y2, describing a ceiling segment whose endpoints are (X1,Y1) and (X2,Y2).
Each of the next C lines contains one integer X, a query asking what happens to a balloon released at the point (X,0).
Constraints
Print one line for each query, in the order the queries are given. If the balloon escapes the hall, the line contains one integer, the x coordinate at which the balloon escapes. Otherwise the line contains two integers X and Y separated by one space, the position (x,y) at which the balloon gets stuck on the ceiling.