Under construction

Still being built. Things may change

Machine Gun

Time limit2sMemory limit512 MB

Summary
For each query, find all enemies inside a right-facing angular wedge and evaluate a polynomial hash of their sorted indices; queries are forced online and the total number of hits is bounded.
Level

Hard8 of 10

Topics
Geometry, Sorting, Binary search, Implementation
Solved
No attempts yet

Problem

Fulanito went to play an old arcade game. In the game, he can place a machine gun anywhere in his base, which consists of all points (x,y)(x, y) with integer coordinates and x<0x < 0. There are NN enemies on the battlefield. The ii-th enemy (1≤i≤N1 \le i \le N) is at position (xi,yi)(x_i, y_i) with xi>0x_i > 0. All positions are given in advance.

A machine gun placed at (xm,ym)(x_m, y_m) covers a viewing angle facing right, centered on the line y=ymy = y_m, whose boundaries are given by the lines y=ym±(x−xm)/2y = y_m \pm (x - x_m)/2. Once placed, it hits every enemy in the region bounded by this angle, including those located on the boundary lines.

Figure 1: Pictorial representation of the sample input

The scoring system used by this game is unnecessarily complicated; many believe that such a system was a big mistake by the developers (who, in response, state with conviction that “it's not a bug, it's a feature!”). Specifically, the score obtained by a given placement of the machine gun is computed by performing the following steps:

  • List the indices (ii between 1 and NN) of all enemies the machine gun hits.
  • Sort the indices in increasing order, and call the sorted values i0<i1<⋯<ik−1i_0 < i_1 < \cdots < i_{k-1}.
  • Compute the score using the formula (∑j=0k−1ij⋅5782344j) mod (109+7)(\sum_{j=0}^{k-1} i_j \cdot 5782344^j) \bmod (10^9 + 7), where a mod ba \bmod b denotes the remainder of dividing aa by bb.
  • Note: A machine gun that hits no enemies receives a score exactly equal to 0.

To get better at this game, Fulanito asks you QQ questions: each query asks for the score that would be obtained if we placed the machine gun at a certain position (xm,ym)(x_m, y_m). To make the problem more challenging, the values of (xm,ym)(x_m, y_m) are not given directly. Instead, values aa and bb are given, which can be used to compute xmx_m and ymy_m through the formulas xm=−1−(p+a) mod (109+7)x_m = -1 - (p + a) \bmod (10^9 + 7) and ym=(p+b) mod (109+7)y_m = (p + b) \bmod (10^9 + 7), where pp is the answer to the previous query (p=0p = 0 when processing the first query).

NOTE: It is guaranteed that the sum of the number of enemies hit across all queries is at most 10610^6.

Input

The input consists of several lines. The first line of the input contains two integers N,QN, Q (1≤N,Q≤1051 \le N, Q \le 10^5), the number of enemies and the number of queries.

The next NN lines of the input contain two integers each: xix_i and yiy_i (1≤xi,yi≤1091 \le x_i, y_i \le 10^9), the coordinates of the position of the ii-th enemy.

The next QQ lines contain two integers each: the values aa and bb (0≤a,b<109+70 \le a, b < 10^9 + 7) that specify each query, as explained in the statement.

Output

For each query, print a single integer containing the answer to the query.

Examples1

  1. Example 1

    Input
    7 2
    2 8
    5 7
    1 6
    4 5
    1 3
    2 2
    4 1
    2 3
    373785639 373785644
    
    Expected output
    626214369
    981053491