Time Limit : sec, Memory Limit : KB
English / Japanese  

Castle in the Sky

 

Tsuruga, the Castle in the Sky, floats in the sky above the country of Aizu. There are days when sunlight is blocked by the castle. Compensation is paid to the inhabitants of the areas where sunlight is blocked for a certain number of days. As the compensation payer for the country of Aizu, you will need to verify that there was no sunlight at the location on that day from the daily location of the astle and the list of locations where compensation has been applied for.

Given the location of the castle in the sky, and a location on the ground in the country of AIzu, write a program to determine if the location was in shadow on that day. You do not need to think about the movement of the castle or the sun, because you will determine at a specific time whether it was in the shadow or not. The location of the sun is a point of no size at $x=y=0,z=10^6$, the castle in the sky is a convex polygon in the plane at $z=100$, and the location on the ground is a point of no size at $z=0$. If the line connecting a point and the sun is blocked by the castle in the sky, the point will be in shadow.

Input

The input is given in the following form.

$N$
$xt_1$ $yt_1$
$xt_2$ $yt_2$
:
$xt_N$ $yt_N$
$Q$
$xa_1$ $ya_1$
$xa_2$ $ya_2$
:
$xa_Q$ $ya_Q$

In the first line, the number of points $N$ ($3 \leq N \leq 3 \times 10^4$) that represent the region of the castle in the sky, is given. In the following $N$ lines, the integer coordinates $xt_i$,$yt_i$ ($-10^8 \leq xt_i,yt_i \leq 10^8$) of the vertices that make up the region are given in counterclockwise around the center of gravity of the region. However, no vertices with the same coordinates are given ($xt_i \ne xt_j$ or $yt_i \ne yt_j$ for $i \ne j$). Also, the area of the region can be considered to be greater than zero. In the subsequent line, the number $Q$ ($1 \leq Q \leq 6 \times 10^4$) of locations where compensation has been applied is given. In the following $Q$ lines, the coordinates $xa_i,ya_i$ ($-10^8 \leq xa_i,ya_i \leq 10^8$) of the locations where compensation was applied are given in integers. Note that the coordinates of the location where the application for compensation was made can be considered to be at least $10^{-3}$ away from the shadow outline of the castle.

Output

For each location where compensation was applied for, output "1" if it is in the shadow, and "0" if it is not, in a line.

Sample Input and Output

Sample Input 1

6
0 0
4 0
6 3
5 5
1 5
0 3
5
2 2
6 6
3 1
5 1
-1 -1

Sample Output 1

1
0
1
0
0

Sample Input 2

4
100000 100000
101000 100000
101000 101000
100000 101000
2
100005 100005
101005 101005

Sample Output 2

0
1