#abc254g. [abc254_g]Elevators

[abc254_g]Elevators

Problem Statement

There is a complex composed of NN 10910^9-story skyscrapers. The skyscrapers are numbered 11 to NN, and the floors are numbered 11 to 10910^9.

From any floor of any skyscraper, one can use a skybridge to get to the same floor of any other skyscraper in one minute.

Additionally, there are MM elevators. The ii-th elevator runs between Floor BiB_i and Floor CiC_i of Skyscraper AiA_i. With this elevator, one can get from Floor xx to Floor yy of Skyscraper AiA_i in xy|x-y| minutes, for every pair of integers x,yx,y such that Bilex,yleCiB_i \\le x,y \\le C_i.

Answer the following QQ queries.

  • Determine whether it is possible to get from Floor YiY_i of Skyscraper XiX_i to Floor WiW_i of Skyscraper ZiZ_i, and find the shortest time needed to get there if it is possible.

Constraints

  • 1leN,M,Qle2times1051 \\le N,M,Q \\le 2 \\times 10^5
  • 1leAileN1 \\le A_i \\le N
  • 1leBi<Cile1091 \\le B_i < C_i \\le 10^9
  • 1leXi,ZileN1 \\le X_i,Z_i \\le N
  • 1leYi,Wile1091 \\le Y_i,W_i \\le 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM QQ A1A_1 B1B_1 C1C_1 A2A_2 B2B_2 C2C_2 vdots\\vdots AMA_M BMB_M CMC_M mathrmquery1\\mathrm{query}_1 mathrmquery2\\mathrm{query}_2 vdots\\vdots mathrmqueryQ\\mathrm{query}_Q

Each query is in the following format:

XiX_i YiY_i ZiZ_i WiW_i

Output

Print QQ lines. The ii-th line should contain -1 if, for mathrmqueryi\\mathrm{query}_i, the destination is unreachable; otherwise, it should contain the minimum number of minutes needed to get there.


Sample Input 1

3 4 3
1 2 10
2 3 7
3 9 14
3 1 3
1 3 3 14
3 1 2 7
1 100 1 101

Sample Output 1

12
7
-1

For the 11-st query, you can get to the destination in 1212 minutes as follows.

  • Use Elevator 11 to get from Floor 33 to Floor 99 of Skyscraper 11, in 66 minutes.
  • Use the skybridge on Floor 99 to get from Skyscraper 11 to Skyscraper 33, in 11 minute.
  • Use Elevator 33 to get from Floor 99 to Floor 1414 of Skyscraper 33, in 55 minutes.

For the 33-rd query, the destination is unreachable, so -1 should be printed.


Sample Input 2

1 1 1
1 1 2
1 1 1 2

Sample Output 2

1