Under construction

Still being built. Things may change

The Great Drone Show

Time limit30sMemory limit512 MB

Summary
Drones rise and fall over k moves, and cables snap once stretched past their limit. For each queried pair, find the first move that disconnects them.
Level

Hard8 of 10

Topics
Union-find, Graph, Sorting
Solved
No attempts yet

Problem

This year's Great Drone Show is planned to be a big success, provided nothing goes wrong and everyone follows 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 use standard Euclidean coordinates in three dimensions, where the ground is the plane z=0z = 0. The starting position of the ii-th drone is (xi,yi,0)(x_i, y_i, 0).

To allow communication during the show, there are mm cables between pairs of drones. Initially the cables also lie on the ground, as straight segments connecting some pairs of drones. The cable network is connected: from every drone there is a sequence of cables to every other drone. To avoid tangling, no two segments cross (they can only share endpoints).

During the show, a sequence of kk moves is performed. Each move changes the height (the zz coordinate) of one drone. Each move is performed smoothly, and it starts only after the previous one ends. During a move, the distances between some drones may change, and the cables can stretch to some degree. Each cable has a maximal length. If its endpoint drones move farther apart than this value, the cable breaks.

The organizers expect some cables to break. However, some pairs of drones must stay able to communicate, directly or indirectly. Given qq critical pairs of drones, determine whether communication between a pair becomes impossible at some point during the show. If it does, determine the move that causes the connection loss.

Input

The first line contains the number of test cases zz (1≤z≤4001 \le z \le 400). Each test case has the following format.

The first line contains nn (2≤n≤5000002 \le n \le 500000). Each of the next nn lines contains two integers xix_i, yiy_i (∣xi∣,∣yi∣≤108|x_i|, |y_i| \le 10^8), the coordinates of the ii-th drone. No two drones share a starting location.

The next line contains mm (1≤m≤3n1 \le m \le 3n), the number of cables. Each of the next mm lines contains three integers uu, vv, ll (1≤u,v≤n1 \le u, v \le n, u≠vu \ne v; 1≤l≤1091 \le l \le 10^9): the two connected drones and the maximal length of the cable. A pair of drones is connected by at most one cable. The length of each cable at its starting position is within its limit.

The next line contains kk (1≤k≤5000001 \le k \le 500000). Each of the next kk lines contains two integers vv, hh (1≤v≤n1 \le v \le n, ∣h∣≤109|h| \le 10^9): the moving drone and its change in height. A positive hh raises the drone, and a negative hh lowers it. You may assume that no drone ever goes below the ground, so all zz coordinates stay non-negative.

Finally, the next line contains qq (1≤q≤5000001 \le q \le 500000), the number of critical pairs. Each of the next qq lines contains two drone numbers uu, vv (1≤u,v≤n1 \le u, v \le n, u≠vu \ne v).

Over all test cases, the sum of nn values does not exceed 10000001000000, and the sums of kk and of qq each do not exceed 10000001000000.

Output

For every test case, print qq integers on separate lines, one per critical pair, in input order. For each pair, print the number of the first move after which the two drones can no longer communicate. Moves are numbered from 1. If a pair stays connected through the whole show, print −1-1.

Examples1

  1. Example 1

    Input
    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
    
    Expected output
    2
    -1
    1
    1