Under construction

Still being built. Things may change

Permian Period Garden

Time limit2sMemory limit512 MB

Summary
Given a W by H rectangle tiled by integer-sided squares, find the side length of the square that holds each plant center.
Level

Medium7 of 10

Topics
Implementation, Sorting, Math
Solved
No attempts yet

Statement

The greenhouse Permian Period Garden is a rectangular plot for growing plants from the Permian period. Paths divide it into squares, and one plant is planted at the center of each square. The size of each square depends on the plant's root system.

Over the year, grass grew over the paths and made the greenhouse harder to tend. To avoid damaging the root system of any plant during garden work, restore the size of the square for each plant from the current plant positions.

Introduce a Cartesian coordinate system with its origin at the lower left corner of the greenhouse. The Ox axis runs along the bottom edge of the plot, and the Oy axis runs along the left edge. Originally the paths were laid parallel to the coordinate axes. The unit length was chosen so that the corner coordinates of every square are integers.

Write a program that takes the size of the greenhouse and the plant coordinates, and outputs the size of the square for each plant.

Input

The first line contains three positive integers WW, HH, and NN. WW is the width of the greenhouse, HH is its length, and NN is the number of plants. Each of the next NN lines contains two numbers xix_i and yiy_i, the coordinates of the ii-th plant (0<xi<W0 < x_i < W, 0<yi<H0 < y_i < H). The side length of each square corresponding to a plant is guaranteed to be an integer, and the squares cover the whole greenhouse.

Output

Output NN integers. Print the size of the square for each plant in the order the plants are given in the input.

Constraints

W,H≤1012W, H \le 10^{12}; N≤2×105N \le 2 \times 10^5. Each test case for this subtask is scored separately.

Hint

The greenhouse from the second example is shown in the figure below.

Examples2

  1. Example 1

    Input
    4 6 3
    1 1
    3 1
    2 4
    
    Expected output
    2
    2
    4
    
  2. Example 2

    Input
    8 8 10
    4.5 7.5
    5.5 7.5
    2 6
    4.5 6.5
    7 7
    5 5
    6 2
    7 5
    2 2
    5.5 6.5
    
    Expected output
    1
    1
    4
    1
    2
    2
    4
    2
    4
    1