A qualified commander should be proficient in the knowledge of military topography. Determining the height of the target is a must.
In the illustration below, the elevation of the two adjacent contours is 10 meters, and the contour of the outermost contour is 500 meters.
Here are the elevation of the four points.
A: 500 meters, because it is on the 500 m contour line.
B: 505 meters, Because it is between the 500 m and 510 m contour lines. For convenience, we take the average, so the height is 505 meters.
C: 510 meters, because it is on the 510 m contour line.
D: 525 meters, Because it is on the top of the mountain, for convenience, we take half an contour-line interval. so the height is 525 meters.
But the real situation is more complicated.
E: 525 meters.
F: 515 meters.
G: 505 meters.
H: 520 meters.
We guarantee that there will be no more complex terrain in the test data. However, it should be noted that the test data will be more complicated for the above two terrains.
The first line is three integers n, k, h.Represents the number of contour lines, the distance between the contour lines (guaranteed as an even number), and the height of a contour line, which we call the base contour line.
The second line is first a number m,indicating the number of points on the base contour, followed by 2 * m integers, indicating the coordinates of the point, x1, y1, x2, y2, ..., xm, ym.
The next n lines give information about the n contours in the same format as above.
The n+3 line is a number w, indicating the number of points questioned.
Next w lines, two integers per line, represent the coordinates of the point of the question.
We guarantee that all contours are inside the basic contours and questioned points are inside or on the basic contours. The coordinate range of all points is 0<=x,y<=300. All points on the contour are given counter-clockwise. The total number of points in all input data does not exceed 200.
A total of w lines. For each question point, output its height.