Олимпиадный тренинг

Задача 30715. Rotating plate


Задача

Темы:
Boy Vasya loves geometry very much. In addition, he really likes to hammer nails into the board. Today he is studying his favorite metal plate, which he is going to nail to a wooden board.

The plate has a shape bounded by a polygon without self-intersections and self-contacts. The plate has a small loop at the first vertex of the polygon.

First, Vasya puts the plate on a board lying on a horizontal table and nails it to the plate through the loop at the first vertex. A driven nail firmly fixes the position of the first vertex, but allows the plate to rotate around it.

Now Vasya wants to drive another nail into the board, which would limit the rotation of the plate, but he has not yet decided where. He has outlined m possible positions where he would like to drive a nail, and for each of them he wants to know by what angle he can turn his plate if he drives a nail into the board at this point. However, as soon as the plate touches the nail, it cannot be turned any further.

Input data format
The first line of the input file contains the number n (3 ≤ n ≤ 2000) — the number of vertices of the polygon. The next n lines contain the coordinates of the polygon's vertices in the order they are traversed. The next line contains the number m (1 ≤ m ≤ 2000) — the number of points that Vasya considers as possible positions for the second nail. The next m lines contain the coordinates of these points. All these points are outside of the initial position of the plate. All coordinates in the input file are integers and do not exceed 106 in absolute value.

Output data format
The output file should contain m lines. On the i-th line print two real numbers αi and βi , where αi — the maximum angle in degrees that the plate can be rotated clockwise if Vasya drives the nail into the i-th point, and βi — the maximum angle in degrees that the plate can be rotated counterclockwise in this case. If the nail does not prevent the plate from turning, print αi = βi = 360. The answer is considered correct if its absolute or relative error relative to the correct one does not exceed 10 −6 .

Enter Output
4
0 0
-3 -3
0-6
3-3
3
-8 0
-2 0
2-1
360.000000000000 360.000000000000
45.000000000000 225.000000000000
251.565051177078 18.434948822922

Explanation


The figure above shows the example test. The rectangle shows the initial position of the plate.
The dots show the positions where Vasya plans to drive the nail.
A nail hammered into the first point does not prevent the plate from turning.
A nail hammered into the second point allows you to rotate the plate by 45 degrees  clockwise or 225 gr. counterclockwise.