For a given polygon g and target points t, print "2" if g contains t, "1" if t is on a segment of g, "0" otherwise.

g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.

Note that the polygon is not necessarily convex.

Constraints

* 3 ≤ n ≤ 100
* 1 ≤ q ≤ 1000
* -10000 ≤ xi, yi ≤ 10000
* No point of the polygon will occur more than once.
* Two sides of the polygon can intersect only at a common endpoint.

Input

The entire input looks like:


g (the sequence of the points of the polygon)
q (the number of queris = the number of target points)
1st query
2nd query
:
qth query


g is given by coordinates of the points p1,..., pn in the following format:


n
x1 y1
x2 y2
:
xn yn


The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them.

Each query consists of the coordinate of a target point t. The coordinate is given by two intgers x and y.

Output

For each query, print "2", "1" or "0".

Example

Input

4
0 0
3 1
2 3
0 3
3
2 1
0 2
3 2


Output

2
1
0
#include<iostream>
#include<cmath>
using namespace std;


struct point{
    int x,y;
};

struct line{
    point s,t;
};
struct bec{
    int x,y;
};

int n,q;
point g[100];

bool kousa(point p1,point p2,point t){
    bec a,b;
    a.x = p2.x-p1.x; a.y = p2.y-p1.y;
    b.x = t.x-p1.x; b.y = t.y-p1.y;
    double d1 = sqrt((double)a.x*(double)a.x + (double)a.y*(double)a.y), d2 = sqrt((double)b.x*(double)b.x + (double)b.y*(double)b.y);
    if(d2==0) return true;
    double c = ((double)a.x*(double)b.x+(double)a.y*(double)b.y)/(d1*d2);
    int ga = a.x*b.y - a.y*b.x;
    int na = a.x*b.x + a.y*b.y;
    if(ga ==0 && na>0 && d1 > d2) return true;
    else return false;
}

int kyori(point p,line l){
    bec p1,p2,bl;
    p1.x = p.x-l.s.x; p1.y=p.y-l.s.y;
    p2.x = p.x-l.t.x; p2.y=p.y-l.t.y;
    bl.x = l.t.x-l.s.x; bl.y = l.t.y-l.s.y;
    double d1,d2,c;
    int c2;
    d1=sqrt((double)p1.x*(double)p1.x+(double)p1.y*(double)p1.y);
    d2=sqrt((double)bl.x*(double)bl.x+(double)bl.y*(double)bl.y);
    c= ((double)p1.x*(double)bl.x+(double)p1.y*(double)bl.y)/(d1*d2);
    c2=(c*100000000000+0.0000000005)/100000000000;
    if(d1==0||sqrt((double)p2.x*(double)p2.x+(double)p2.y*(double)p2.y)==0) return 1;
    else if(c2==1 && d1<=d2) return 1;
    else return 0;
}

int kou(line l,line m){
    long ta,tb,tc,td;
    ta=(m.s.x-m.t.x)*(l.s.y-m.s.y)+(m.s.y-m.t.y)*(m.s.x-l.s.x);
    tb=(m.s.x-m.t.x)*(l.t.y-m.s.y)+(m.s.y-m.t.y)*(m.s.x-l.t.x);
    tc=(l.s.x-l.t.x)*(m.s.y-l.s.y)+(l.s.y-l.t.y)*(l.s.x-m.s.x);
    td=(l.s.x-l.t.x)*(m.t.y-l.s.y)+(l.s.y-l.t.y)*(l.s.x-m.t.x);
    if(tc*td<0 && ta*tb<0){
        return 1;
    }
    else{
        if(kyori(l.s,m)==1||kyori(l.t,m)==1||kyori(m.s,l)==1||kyori(m.t,l)==1) return 1;
        else return 0;

    }

}


int solve(point t){
    int k=0;
    for(int i=0;i<n;i++){
        if(i!=n-1){
            if(kousa(g[i],g[i+1],t)) return 1;
        }
        else{
            if(kousa(g[i],g[0],t)) return 1;
        }
    }

    bec a,b;
    point g1,g2;
    for(int i=0;i<n;i++){
        if(i!=n-1){
            g1=g[i];
            g2=g[i+1];
        }
        else{
            g1=g[i];
            g2=g[0];
        }
        if(g1.y>g2.y){
            a.x = g2.x-t.x; a.y = g2.y-t.y;
            b.x = g1.x-t.x; b.y = g1.y-t.y;
        }
        else{
            a.x = g1.x-t.x; a.y = g1.y-t.y;
            b.x = g2.x-t.x; b.y = g2.y-t.y;
        }

        long ga = a.x*b.y-a.y*b.x;

        line l,m;
        l.s = g1; l.t = g2;

        m.s = t;
        m.t.x = 10001;
        m.t.y = t.y;

        if(kou(l,m)==1 &&ga >0 && min(g1.y,g2.y)!= t.y) k++;

    }

    int ans =k%2;
    if(ans==1) return 2;
    else return 0;


}

int main(){
    cin>>n;
    int x,y;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        g[i].x = x;
        g[i].y = y;
    }

    cin>>q;
    for(int i=0;i<q;i++){
        point t;
        cin>>x>>y;
        t.x = x;
        t.y = y;
        cout<<solve(t)<<endl;
    }
}
