New Home

Stores of k types each occupy a point and an open year interval; for each (location, year) query, report the maximum over types of the distance to the nearest open store of that type, or -1 if some type is missing.

Hard9Segment treeBinary searchSortingDivide and conquerNo attempts yetTime limit5sMemory limit1024 MB

Problem

Wu-Fu Street is a perfectly straight street. It is described as a one-dimensional number line, so every building on it sits at a single number. Xiao-Ming the time traveler knows every store that opened, is open, or will open on the street: there are nn stores of kk types. Store ii is given by four integers xix_i, tit_i, aia_i, bib_i, meaning the location of the store, the type of the store, the year its business starts, and the year its business ends. Store ii is open in year yy when aiybia_i \le y \le b_i.

Xiao-Ming wants to pick a year and a location on Wu-Fu Street to live in, and he narrowed his preference list to qq pairs of a location and a year. Pair ii is given by two integers lil_i, yiy_i. He rates a pair by its inconvenience index, the inaccessibility of the store type that is hardest to reach. The inaccessibility of type tt for a pair is the distance from the location to the nearest type-tt store that is open in that year, so the inconvenience index is the largest of those distances over all kk types. In some years Wu-Fu Street does not carry all kk types. The inconvenience index of such a pair is 1-1.

Find the inconvenience index of every pair.

Input

The first line contains three integers nn, kk, qq: the number of stores, the number of types, and the number of queries (1n,q3×1051 \le n, q \le 3 \times 10^5, 1kn1 \le k \le n).

Each of the next nn lines describes one store with four integers xix_i, tit_i, aia_i, bib_i (1xi,ai,bi1081 \le x_i, a_i, b_i \le 10^8, 1tik1 \le t_i \le k, aibia_i \le b_i).

Each of the next qq lines contains one query, two integers lil_i and yiy_i (1li,yi1081 \le l_i, y_i \le 10^8).

Output

Print qq integers, one per line, in the order the queries are given. The ii-th of them is the inconvenience index of the ii-th query.

Hint

The first sample has four stores, two types, and four queries.

  • First query: Xiao-Ming lives at location 5 in year 3. Stores 1 and 2 are open that year, the distance to store 1 is 2, and the distance to store 2 is 4. The answer is 4.
  • Second query: he lives at location 5 in year 6. Stores 1 and 3 are open and both are at distance 2. The answer is 2.
  • Third query: he lives at location 5 in year 9. Stores 1 and 4 are open and both have type 1, so no store of type 2 is open. The answer is 1-1.
  • Fourth query: the same situation, so the answer is 1-1.

The second sample has two stores, one type, and three queries. Both stores are at location 1, and every query asks about location 1. At least one store is open in the first two queries, so the answer is 0. Both stores are closed in the third query, so the answer is 1-1.

The third sample has one store and one query. The distance between the two locations is 99999999.