Secret Agent

Given a planar straight-line graph (castle walls) where crossing a wall costs its height, find the minimum cost to travel between successive query points, starting from infinity.

Hard9GraphGeometryShortest pathDFSNo attempts yetTime limit2sMemory limit512 MB

Problem

Two thousand years ago the castle of the city state Inho stood on this very spot. The castle has NN watchtowers numbered 11 through NN and MM walls, each wall joining two towers. Every wall is a straight segment, no two walls meet at any point other than a tower, and the walls let you walk from any tower to every other tower. King Inho of Inho hid the state secrets inside that castle.

King Minseok of the rival city state Minseok sends a secret agent in to dig the secrets out. The agent is so fast that travel time is negligible whenever no wall blocks the way. Climbing over a wall costs exactly the height of that wall. The agent cannot pass through a tower, so every crossing happens at a point of a wall that is not a tower.

Minseok orders the agent to visit QQ spots in the given order. No spot lies on a wall or on a tower. The agent starts infinitely far away from the castle, goes to spot 11, then to spot 22, and so on. Find the minimum time each leg of the trip takes.

Input

The first line contains the number of towers NN (1N2000001 \le N \le 200\,000) and the number of walls MM (N1MN+100N-1 \le M \le N+100).

Each of the next NN lines contains the coordinates xix_i and yiy_i of tower ii. (xi,yi109|x_i|, |y_i| \le 10^9)

Each of the next MM lines contains the numbers uiu_i and viv_i of the two towers a wall joins, followed by the height hih_i of that wall. (1ui,viN1 \le u_i, v_i \le N, uiviu_i \ne v_i, 1hi1091 \le h_i \le 10^9)

At most one wall joins a given pair of towers, and no two walls meet at a point other than a tower. Every tower is reachable from every other tower along the walls.

The next line contains the number of orders QQ (1Q2000001 \le Q \le 200\,000).

Each of the next QQ lines contains the coordinates aia_i and bib_i of the ii-th spot. (ai,bi109|a_i|, |b_i| \le 10^9)

No spot lies on a wall or on a tower.

Output

Print QQ lines. Line ii holds the minimum time needed to travel from spot i1i-1 to spot ii. Spot 00 sits at (,)(\infty, \infty), infinitely far from the castle.

Hint

The picture below shows a castle with 4 towers and 5 walls, together with the 3 spots visited in order.