Railway Trip 2

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

IOI Railway Company is operating lines on a railway track. There are NN stations in a straight line, numbered from 11 to NN. For each ii (1iN11 ≤ i ≤ N - 1), Station ii and Station i+1i + 1 are connected directly by a railway track.

IOI Railway Company is operating MM lines, numbered from 11 to MM. In Line jj (1jM1 ≤ j ≤ M), the starting station is Station A_jA\_j, and the terminal station is Station B_jB\_j. A train stops at every station. Namely, if A_j<B_jA\_j < B\_j a train of Line jj stops at Station A_jA\_j, Station A_j+1A\_j + 1, \dots, Station B_jB\_j, in this order. If A_j>B_jA\_j > B\_j, a train of Line jj stops at Station A_jA\_j, Station A_j1A\_j - 1, \dots, Station B_jB\_j, in this order.

JOI-kun is a traveler. He has QQ travel plans. In the kk-th plan (1kQ1 ≤ k ≤ Q), he travels from Station S_kS\_k to Station T_kT\_k by taking lines.

However, JOI-kun is tired from a long journey. He wants to take a vacant train and get a seat. Thus, JOI-kun decided that he takes a train of a line at a station only if it is the KK-th or earlier stop from the starting station of the line. In other words, if A_j<B_jA\_j < B\_j, he can take a train of Line jj only at Station A_jA\_j, Station A_j+1A\_j + 1, \dots, Station minA_j+K1,B_j1\min{\\{A\_j + K - 1, B\_j - 1\\}}. If A_j>B_jA\_j > B\_j, he can take a train of Line jj only at Station A_jA\_j, Station A_j1A\_j - 1, \dots, Station maxA_jK+1,B_j+1\max{\\{A\_j - K + 1, B\_j + 1\\}}. JOI-kun will get out of the train at a station between the station next to where he takes the train and the terminal station, inclusive.

Under these conditions, JOI-kun wants to minimize the number of times of taking trains.

Given the information of the lines of IOI Railway Company and JOI-kun’s plans, write a program which calculates, for each of JOI-kun’s plans, the minimum number of times of taking trains needed for JOI-kun to achieve it.

입력

Read the following data from the standard input. Given values are all integers.

\begin{align\*}\&N\\,K \\\ & M \\\ & A\_1\\,B\_1 \\\ & A\_2\\,B\_2 \\\ & \vdots \\\ & A\_M\\,B\_M \\\ & Q \\\ & S\_1\\,T\_1 \\\ & S\_2\\,T\_2 \\\ & \vdots \\\ & S\_Q\\,T\_Q\end{align\*}

출력

Write QQ lines to the standard output. The kk-th line (1kQ1 ≤ k ≤ Q) should contain the minimum number of times of taking trains needed for JOI-kun to achieve the kk-th plan. If it is not possible to achieve the kk-th plan, output -1.

제한

  • 2N100,0002 ≤ N ≤ 100\\,000.
  • 1KN11 ≤ K ≤ N - 1.
  • 1M200,0001 ≤ M ≤ 200\\,000.
  • 1A_jN1 ≤ A\_j ≤ N (1jM1 ≤ j ≤ M).
  • 1B_jN1 ≤ B\_j ≤ N (1jM1 ≤ j ≤ M).
  • A_jB_jA\_j \ne B\_j (1jM1 ≤ j ≤ M).
  • (A_j,B_j)(A_k,B_k)(A\_j , B\_j) \ne (A\_k, B\_k) (1j<kM1 ≤ j < k ≤ M).
  • 1Q50,0001 ≤ Q ≤ 50\\,000.
  • 1S_kN1 ≤ S\_k ≤ N (1kQ1 ≤ k ≤ Q).
  • 1T_kN1 ≤ T\_k ≤ N (1kQ1 ≤ k ≤ Q).
  • S_kT_kS\_k \ne T\_k (1kQ1 ≤ k ≤ Q).
  • (S_k,T_k)(S_l,T_l)(S\_k, T\_k) \ne (S\_l , T\_l) (1k<lQ1 ≤ k < l ≤ Q).