Inspecting Radars

Radars Inc. is a worldwide renowned radar maker, whose excellent reputation lies on strict quality assurance procedures and a large variety of radar models that fit all budgets. The company hired you to develop a detailed inspection that consists of a sequence of E experiments on a specific surveillance model. There is a field represented with a polar coordinate plane that contains N objects placed at positions with integer polar coordinates. The inspected model is located at the origin (0,0) of the field and can detect objects at a distance less than its detection range R through a scan area defined by four adjustment parameters α, A, h, and H, whose meaning is illustrated with the following figure: Formally, the scan area of the model is the region described by the set of polar points {(r,θ)|h≤r<h+H, α≤θ≤α+A} α, A, h and H are four integer values where: • α specifies the start angle of the radar’s scan area (0 ≤ α < 360); • A specifies the opening angle of the radar’s scan area (0 ≤ A < 360); • h gives the internal radius of the radar’s scan area (0 ≤ h < R); and • H gives the height of the radar’s scan area (1 ≤ H ≤ R). An object placed at (r,θ) will be displayed by the model if h ≤ r < h+H and α ≤ θ ≤ α+A, where the last inequality should be understood modulo 360o (i.e., adding and comparing angles in a circle). Given N objects placed on the field, you must develop an inspection of the surveillance model through the implementation of E experiments with specific parameterizations. For each experiment you have to find the maximal number of objects on the field that the radar should display if the parameters α (0 ≤ α < 360) and h (0 ≤ h < R) are free to set (as integer numbers), and the parameters H (1 ≤ H ≤ R) and A (0 ≤ A < 360) are given.

2/3 Input The input consists of several test cases. Each test case is described as follows: • A line with two integer numbers N and R separated by blanks, representing (respectively) the number of objects located on the field and the detection range of the model (1 ≤ N ≤ 104, 2 ≤ R ≤ 102). • Each one of the following N lines contains two integer numbers ri and θi separated by blanks, specifying the integer polar coordinates (ri,θi) of the i-th object (1 ≤ ri < R, 0 ≤ θi < 360, 1 ≤ i ≤ N). • The next line has an integer number E indicating the number of experiments of the inspection (1 ≤ E ≤ 102). • Each one of the following E lines contains two integer numbers Hj and Aj separated by blanks, representing (respectively) the fixed height and the fixed opening angle that parameterize the j-th experiment(1≤Hj ≤R,0≤Aj <360,1≤j≤E). For each test case you can suppose that there are not two different objects placed at the same integer polar coordinate. The last test case is followed by a line containing two zeros. Output For each test case of the input, print E lines where the j-th line contains the maximal number of objects on the field that the radar should display according to the parameterization given for the j-th experiment (1 ≤ j ≤ E). Sample Input 6 100 15 7 15 60 40 15 50 15 45 30 45 90 2 21 100 359 9 100 15 7 15 60 40 15 50 15 45 30 45 90 40 45 50 45 78 100 6 100 359 11 30 10 30

3/3 11 29 5 30 11 10 00 Sample Output 1 6 9 5 3 3 2 2