City Center X24039


Statement
 

pdf   zip

html

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.

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 1≤ n≤25000, 1≤ e≤25000 and 1≤ k≤25000. 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..n, each following line contains two integers xiN and yiN, which denote the coordinates of the crossing of i-th Horizontal Street and 0th Vertical Street. Each yiN is greater than the previous one.

Then, for i=1..e, each following line contains two integers xiE and yiE, which denote the coordinates of the crossing of 0th Horizontal Street and i-th Vertical Street. Each xiN is greater than the previous one.

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

Each point in the city center has coordinates (x,y) such that −2000000000≤ x,y≤ 2000000000.

Output

Output should consist of k rows. In i-th row of input give the address of i-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. This problem is being checked.
    User solutions
    C++