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>
#include <cstdio>
#include <algorithm>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
typedef long long ll;
const int maxp = 110;
int sgn(double x){
    if(fabs(x)<eps){
        return 0;
    }
    if(x<0){
        return -1;
    }else{
        return 1;
    }
}
struct Point{
    double x,y;
    Point(){}
    Point(double _x,double _y){
        x = _x;
        y = _y;
    }
    void input(){
        scanf("%lf%lf",&x,&y);
    }
    bool operator < (Point b)const{
        return sgn(x-b.x)==0?sgn(y-b.y)<0:x<b.x;
    }
    bool operator == (Point b)const{
        return sgn(x-b.x)==0&&sgn(y-b.y)==0;
    }
    Point operator -(const Point &b)const{
        return Point(x-b.x,y-b.y);
    }
    double operator ^(const Point &b)const{
        return x*b.y-y*b.x;
    }
    double distance(Point p){
        return hypot(x-p.x,y-p.y);
    }
};
struct Line{
    Point s,e;
    Line(){}
    Line(Point _s,Point _e){
        s  = _s;
        e = _e;
    }
    // 这不能判断点是不是在线段区间内，在线段的延长线也满足
    // bool pointonseg(Point p){
    //     return sgn((p-s)^(e-s))==0&&sgn((p-s)^(p-e))<=0;
    // }
    //1 点在线段的逆时针方向
    //2 点在线段的顺时针方向
    //3 点在线段上
    int relation(Point p){
        int c = sgn((p-s)^(e-s));
        if(c < 0){
            return 1;
        }else if(c>0){
            return 2;
        }else{
            return 3;
        }
    }
    //4 点在线段上
    //6 点在线段后面
    //7 点在线段的前面
    int pointonseg(Point p){
        int c = sgn((p-s)^(p-e));
        if(c<0){
            return 4;
        }else{
            if((p.x-s.x)*(s.x-e.x)>0.0||(p.x==s.x&&(p.y-s.y)*(s.y-e.y)>0.0)){
                return 6;
            }else if((p.x-e.x)*(e.x-s.x)>0.0||(p.x==e.x&&(p.y-e.y)*(e.y-s.y)>0.0)){
                return 7;
            }else{
                return 4;
            }
        }
    }
};
struct polygon{
    int n;
    Point p[maxp];
    Line l[maxp];
    void input(int _n){
        n = _n;
        for(int i = 0;i < n;++i ){
            p[i].input();
        }
    }
    // 给凸包连边
    void getline(){
        for(int i = 0;i < n;++i ){
            l[i] = Line(p[i],p[(i+1)%n]);
        }
    }
    // 点和多边形的关系
    // 3 点上
    // 2 边上
    // 1 内部
    // 0 外部
    int relationpoint(Point q){
        for(int i = 0;i < n;++i ){
            if(p[i] == q){
                return 3;
            }
        }
        getline();
        for(int i = 0;i < n;++i ){
            // if(l[i].pointonseg(q)){
            //     return 2;
            // }
            if(l[i].relation(q)==3&&l[i].pointonseg(q)==4){
                return 2;
            }
        }
        int cnt = 0;
        for(int i = 0;i < n;++i ){
            int j = (i+1)%n;
            int k = sgn((q-p[j])^(p[i]-p[j]));
            int u = sgn(p[i].y-q.y);
            int v = sgn(p[j].y-q.y);
            if(k>0&&u<0&&v>=0){
                cnt++;
            }
            if(k<0&&v<0&&u>=0){
                cnt--;
            }
        }
        return cnt!=0;
    }
};
int main(){
    int N;
    scanf("%d",&N);
    polygon pp;
    pp.input(N);
    int q;
    scanf("%d",&q);
    Point p;
    while(q--){
        p.input();
        int ans = pp.relationpoint(p);
        if(ans==1){
            printf("2\n");
        }else if(ans == 2 || ans == 3){
            printf("1\n");
        }else{
            printf("0\n");
        }
    }
  
    return 0;
}
