Connect Highways

Given two planar connected networks, find the Red-Blue junction pair allowed to be joined by a segment, following a fixed angular tie-breaking rule.

Hard9GeometrySortingGraphBinary searchNo attempts yetTime limit0.4sMemory limit32 MB

Problem

Byteland has two highway networks, one run by Red and one run by Blue. Each network consists of junction points and straight segments that join pairs of junction points. Inside one network two segments meet only at junction points and nowhere else. Each network is connected, so you can travel between any two junction points of the same network along its segments. No junction point belongs to both networks. Segments of different networks may cross each other.

The two companies are merging. They want to join the networks by building one straight segment between a junction point of Red and a junction point of Blue. Apart from its own two endpoints, the new segment must share no point with an existing segment.

Input

The input holds the description of the Red network followed by the description of the Blue network. The first line of a description has two integers NN and MM (2N2000002 \le N \le 200000, 1M7000001 \le M \le 700000), the number of junction points and the number of segments. Each of the next NN lines has two integers xx and yy (1000000x,y1000000-1000000 \le x, y \le 1000000), the coordinates of a junction point. Junction points are numbered from 11 to NN in the order they appear. Each of the next MM lines has two integers pp and qq (1p,qN1 \le p, q \le N, pqp \ne q), the endpoints of a segment.

No junction point lies on a segment of the other network.

Output

Print two integers uu and vv, the endpoints of the new segment. uu is a junction point of Red, vv is a junction point of Blue, and the segment between them meets no segment of either network except at uu and vv.

Several pairs can satisfy that, so the answer is fixed by the rule below.

Call a point PP higher than a point QQ if PP has the larger yy, or the same yy and the larger xx. Let tt be the highest of all junction points of both networks, and let bb be the highest junction point of the network that does not contain tt. Consider only those junction points aa of the network of tt that are higher than bb and can be joined to bb under the condition above. Such an aa always exists. Among them take the one whose vector from bb to aa makes the smallest counterclockwise angle with the positive xx direction. That angle is always at least 00 and less than 180180 degrees. If two points give the same angle, take the one closer to bb. For the pair chosen this way, print the number of the Red junction point first and the number of the Blue junction point second.

Hint

The figure shows the two networks of the example, with the connecting segment that the rule selects drawn as a dashed line.