Slingshot

For each of M queries (a, b), find the minimum time to move manure from a to b using the tractor (cost equals distance) plus at most one slingshot that flies from x to y in time t.

Hard8Divide and conquerSortingPrefix sumGreedyNo attempts yetTime limit2sMemory limit512 MB

Problem

Of all the chores on the farm, Farmer John dislikes hauling manure the most. To cut the work down he comes up with an odd plan: instead of moving manure between two points in a cart behind his tractor, he shoots it through the air with a giant manure slingshot. (what could possibly go wrong)

John's farm runs along one long straight road, so every location on the farm is a single coordinate along that road, a point on the number line. John builds NN slingshots (1N1051 \leq N \leq 10^5). Slingshot ii is given by three integers xix_i, yiy_i, and tit_i: it shoots manure from position xix_i to position yiy_i in only tit_i units of time.

John has MM piles of manure to move (1M1051 \leq M \leq 10^5). Pile jj has to go from position aja_j to position bjb_j. Hauling manure a distance of dd with the tractor takes dd units of time. John hopes to cut that down by allowing up to one slingshot use for each pile. Time the tractor spends moving with no manure in it does not count.

For each of the MM piles of manure, find the smallest possible transport time, given that John may use at most one slingshot along the way.

Input

The first line contains NN and MM. Each of the next NN lines describes one slingshot with the integers xix_i, yiy_i, and tit_i (0xi,yi,ti1090 \leq x_i, y_i, t_i \leq 10^9). Each of the final MM lines describes one pile of manure that has to be moved, with the integers aja_j and bjb_j.

Output

Print MM lines, one for each pile of manure, each holding the smallest time needed to move that pile.

Hint

In the example, the first pile of manure has to move from position 1 to position 12. Without a slingshot that takes 11 units of time. With the first slingshot it takes 1 unit of time to move the manure to position 0, the launch point, 1 unit of time to fling it through the air to position 10, the landing point, and then 2 units of time to move it to position 12, for a total of 4. The second pile is fastest with no slingshot at all, and the third pile is fastest with the second slingshot.