#P2585. 「APIO2018」新家

「APIO2018」新家

Description

Wu-Fu Street is an incredibly straight street that can be described as a one-dimensional number line, and each building’s location on the street can be represented with just one number. Xiao-Ming the TimeTraveler knows that there are n stores of k store-types that had opened, has opened, or will open on the street. The ii-th store can be described with four integers: xi,x_i, ti,t_i, ai,a_i, bi,b_i, representing the store’s location, the store’s type, the year when it starts its business, and the year when it is closed.

Xiao-Ming the Time Traveler wants to choose a certain year and a certain location on Wu-Fu Street to live in. He has narrowed down his preference list to qq location-year pairs. The ii-th pair can be described with two integers: li,l_i, yi,y_i, representing the location and the year of the pair. Now he wants to evaluate the life quality of these pairs. He defines the inconvenience index of a location-year pair to be the inaccessibility of the most inaccessible store-type of that pair. The inaccessibility of a location-year pair to store-type tt is defined as the distance from the location to the nearest type-tt store that is open in the year. We say the ii-th store is open in the year yy if aiybi.a_i ≤ y ≤ b_i. Note that in some years, Wu-Fu Street may not have all the kk store-types on it. In that case, the inconvenience index is defined as 1−1.

Your task is to help Xiao-Ming find out the inconvenience index of each location-year pair.

Input

The first line of input contains integer numbers n,n, k,k, and qq: number of stores, number of types and number of queries (1n,q3105,1kn)(1 ≤ n, q ≤ 3\cdot 10^5, 1 ≤ k ≤ n).

Next nn lines contain descriptions of stores. Each description is four integers: xi,x_i, ti,t_i, ai,a_i, and bib_i (1xi,ai,bi108,(1 ≤ x_i, a_i, b_i ≤ 10^8, 1tik,1 ≤ t_i ≤ k, aibi)a_i ≤ b_i).

Next qq lines contain the queries. Each query is two integers: lil_i, and yiyi (1li,(1 ≤ l_i, yi108)y_i ≤ 10^8).

Output

Output qq integers: for each query output its the inconvenience index.

4 2 4
3 1 1 10
9 2 2 4
7 2 5 7
4 1 8 10
5 3
5 6
5 9
1 10
4
2
-1
-1
2 1 3
1 1 1 4
1 1 2 6
1 3
1 5
1 7
0
0
-1
1 1 1
100000000 1 1 1
1 1
99999999

Limits And Hints

Subtask 1 (5 points): n,q400n,q\leq 400

Subtask 2 (7 points): n,q6×104,n,q\leq 6\times 10^4, k400k\leq 400

Subtask 3 (10 points): n,q3×105,n,q\leq 3\times 10^5, ai=1,bi=108a_i=1,b_i=10^8 for all stores.

Subtask 4 (23 points): n,q3×105,n,q\leq 3\times 10^5, ai=1a_i=1 for all stores.

Subtask 5 (35 points): n,q6×104n,q\leq 6\times 10^4

Subtask 6 (20 points): n,q3×105n,q\leq 3\times 10^5