City Center X24039


Statement
 

pdf   zip

The city center of the capital of Meashara contains two kinds of streets: horizontal and vertical ones. Vertical ones go roughly from South to North; there are sometimes deviations, but the angle between the street and Sorth-Nouth is never greater than 30 degrees. Likewise, horizontal ones go roughly from West to East, and the deviation is never greater than 30 degrees. Both vertical and horizontal streets are numbered with consecutive integers.

Even though some street fragments don’t go strictly North or East, the structure of the city center has some regularity: the region between two neighboring vertical streets, and two neighboring horizontal streets, is always a parallelogram.

image

George Zynoulus is running a company producing navigational systems. Currently the navigational system is able to tell the receiver’s coordinates. However, this is not enough for the citizens, who rather want to know their current address. Your task is to, given a description of streets and coordinates, quickly determine the address of the crossing that the receiver is currently on, that is, the numbers of horizontal and vertical streets which cross there.

Input

The first row contains three numbers 1n250001\leq n\leq25000, 1e250001\leq e\leq25000 and 1k250001\leq k\leq25000. These are, respectively, number assigned to the last horizontal street, number assigned to the last vertical street, and the number of queries (coordinates of crossings recorded by the receiver).

We assume that the 0th Vertical Street and the 0th Horizontal Street cross at (0,0). Point (1,0) is 1 Measharan meter to the East, and point (0,1) is 1 Measharan meter to the North.

For i=1..ni=1..n, each following line contains two integers xiNx^N_i and yiNy^N_i, which denote the coordinates of the crossing of ii-th Horizontal Street and 00th Vertical Street. Each yiNy^N_i is greater than the previous one.

Then, for i=1..ei=1..e, each following line contains two integers xiEx^E_i and yiEy^E_i, which denote the coordinates of the crossing of 0th Horizontal Street and ii-th Vertical Street. Each xiNx^N_i is greater than the previous one.

Then, for i=1..ki=1..k, each following line contains two numbers xix_i and yiy_i. These are coordinates of the crossing that we have to find.

Each point in the city center has coordinates (x,y)(x,y) such that 2000000000x,y2000000000-2000000000\leq x,y\leq 2000000000.

Output

Output should consist of kk rows. In ii-th row of input give the address of ii-th crossing.

Public test cases
  • Input

    4 6 6
    2 4
    0 8
    -1 10
    -1 13
    1 0
    3 -1
    7 1
    11 1
    14 0
    16 -1
    -1 13
    0 13
    13 5
    13 5
    7 9
    14 8
    

    Output

    4 0
    4 1
    1 4
    1 4
    2 3
    2 5
    
  • Information
    Author
    Eryk Kopczynski
    Language
    English
    Official solutions
    Unknown.
    User solutions
    C++