Permian Period Garden
Time limit2sMemory limit512 MB
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 , , and . is the width of the greenhouse, is its length, and is the number of plants. Each of the next lines contains two numbers and , the coordinates of the -th plant (, ). 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 integers. Print the size of the square for each plant in the order the plants are given in the input.
Constraints
; . Each test case for this subtask is scored separately.
Hint
The greenhouse from the second example is shown in the figure below.
