#P12806. [AMPPZ 2019] The Great Drone Show

[AMPPZ 2019] The Great Drone Show

Description

This year’s Great Drone Show is going to be a stunning success! Well, if nothing goes horribly wrong. And if everybody sticks to the plan.

The plan is worked out in every detail. At the beginning, nn drones are parked on the ground. To describe their movement, we introduce standard Euclidean coordinates in three dimensions, in which the ground is the z=0z = 0 plane. The starting position of the ii-th drone is then described as (xi,yi,0)(x_i, y_i, 0).

To allow communication during the show, there are mm cables between pairs of drones. The cables initially also lie on the ground, in the form of straight segments connecting some pairs of drones. It is known that from every drone there is a sequence of cables to every other drone (the cable network is connected). Moreover, to avoid tangling the cables, no two segments cross each other (they can only have common endpoints).

During the show a sequence of kk moves will be performed. Every move consists of changing the height (i.e. the zz-coordinate) of one of the drones. Each move will be performed smoothly and will start only after the previous one ends. During a move, the distance between some drones may change – fortunately, the cables can stretch to some degree. For every cable we know the maximal length it can have – if its endpoint drones go further than this value, the cable breaks.

The show organizers are prepared for some cables to break. However, some pairs of drones must remain able to communicate, directly or indirectly. Given qq specific, critical pairs of drones, determine if communication between these pairs becomes impossible at some point during the show, and if so, determine the move which will cause the connection loss.

Input Format

The first line of input contains the number of test cases zz (1z4001 \le z \le 400). The test cases follow, each one in the following format:

  • The first line contains the number of drones nn (2n500 0002 \le n \le 500\ 000). Each of the following nn lines contains two integers xi,yix_i, y_i (xi,yi108|x_i|, |y_i| \le 10^8) – the xx and yy coordinates of the ii-th drone. No two drones occupy the same starting location.
  • The next line contains an integer mm (1m3n1 \le m \le 3 \cdot n) – the number of cables. Each of the following mm lines describes a single cable, and contains three integers u,v,lu, v, l (1uvn1 \le u \ne v \le n; 1l1091 \le l \le 10^9) – the numbers of connected drones and its maximal length, respectively. A pair of drones can be connected by at most one cable. Every cable’s length at its starting position fits within the given length limit.
  • The next line contains the number of moves kk (1k500 0001 \le k \le 500\ 000). Each of the following kk lines contain two integers v,hv, h (1vn1 \le v \le n; h109|h| \le 10^9) – number of the moving drone and its change of height (positive if the drone raises, negative if it falls). You may assume that no drone ever falls below the ground (the zz coordinates remain non-negative).
  • Finally, the following line contains an integer qq (1q500 0001 \le q \le 500\ 000) – the number of critical pairs to be checked. In the next qq lines, these pairs are described – each one contains two drone numbers u,vu, v (1uvn1 \le u \ne v \le n).

The sum of nn values over all test cases does not exceed 1 000 0001\ 000\ 000. Similarly, both the sum of kk values and the sum of qq values also do not exceed 1 000 0001\ 000\ 000.

Output Format

For every test case, output in separate lines qq integers – the answers for each critical pair. For every such pair of drones, output the number of the first move after which the drones lost the ability to communicate. The moves are numbered starting from 1. If a critical pair remains connected during the whole show, output 1-1 instead.

1
4
0 0
0 12
0 24
0 25
3
1 2 13
2 3 13
3 4 1
4
3 1
2 6
3 1
2 -6
4
1 2
2 3
3 4
1 4
2
-1
1
1