Posters on the wall

Given up to 50000 non-overlapping axis-aligned rectangles, answer online queries that ask for the total rectangle area inside a query rectangle, with coordinates decoded from the previous answer.

Hard8Segment treeSortingBinary searchPrefix sumNo attempts yetTime limit2sMemory limit1024 MB

Problem

Deep inside a secret base there is a wall covered with rectangular posters. The posters are hard to come by, so they are placed without overlapping.

Every now and then a batch of new posters worth a place on the wall arrives, and the keepers have to decide where to put them. Your part of that process is one step: for a candidate position, compute the total area of the posters already hanging that a new poster placed there would cover.

You are given nn grey rectangles in a plane, no two of which overlap. Answer qq queries. Each query gives one rectangle and asks for the total grey area inside it. A query does not change the plane.

The answers have to be produced online. The coordinates of each query are encoded with the answer to the previous query, so you cannot read every query before answering the first one.

Input

The first line contains five integers rr, cc, nn, qq, mm (1r,c<m109+91 \leq r, c < m \leq 10^9 + 9, 0n,q500000 \leq n, q \leq 50\,000): the height of the wall, the width of the wall, the number of posters on the wall, the number of queries, and the modulus used to encode the queries.

Each of the next nn lines contains four integers x1,y1,x2,y2x_1, y_1, x_2, y_2 (0x1,x2r0 \leq x_1, x_2 \leq r, 0y1,y2c0 \leq y_1, y_2 \leq c), two opposite corners of one poster.

Each of the last qq lines contains five integers x1,y1,x2,y2,vx_1', y_1', x_2', y_2', v, each between 00 and m1m - 1 inclusive. Let ll be the answer to the previous query, with l=0l = 0 for the first query. The real coordinates follow from the formulas below.

xi=(xi+lv)(modm)x_i = (x_i' + l \cdot v) \pmod m

yi=(yi+lv)(modm)y_i = (y_i' + l \cdot v) \pmod m

The decoded values x1,y1,x2,y2x_1, y_1, x_2, y_2 are two opposite corners of the query rectangle and satisfy 0x1,x2r0 \leq x_1, x_2 \leq r and 0y1,y2c0 \leq y_1, y_2 \leq c.

In some inputs vv is zero in every query. The encoding then leaves the coordinates unchanged.

Output

For each query print one line with a single integer: the total grey area inside the query rectangle.

Hint

The picture below shows the whole plane of the first example.

The second example encodes the same four queries as the first one with a nonzero vv. After decoding, the queries of the two examples agree, and so do the answers.