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 <vector>
#include <iomanip>
#include <algorithm>
#define EPS (1e-10)
using namespace std;
static const int COUNTER_CLOCKWISE=1;
static const int CLOCKWISE=-1;
static const int ONLINE_BACK=2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT=0;
class Point{
public:
    double x,y;
    Point(double x=0, double y=0):x(x),y(y){}
    Point operator +(const Point &p){
        return Point(x+p.x,y+p.y);
    }
    Point operator -(const Point &p){
        return Point(x-p.x,y-p.y);
    }
    Point operator *(double k){
        return Point(k*x,k*y);
    }
    Point operator /(double k){
        return Point(x/k,y/k);
    }

    double norm(){
        return x*x+y*y;
    }
    double abs(){
        return sqrt(norm());
    }
};
typedef Point Vector;
vector<Point>g;
struct segment{
    Point p1,p2;
};
typedef segment Line;
class Circle{
public:
    Point c;
    double r;
    Circle (double x=0, double y=0,double r=0):c(x,y),r(r){}
};
double dot(const Vector &v1,const Vector &v2){
    return v1.x*v2.x+v1.y*v2.y;
}
double cross(const Vector &v1,const Vector &v2){
    return v1.x*v2.y-v1.y*v2.x;
}
bool isParallel(const Vector &v1,const Vector &v2){
    if(fabs(cross(v1,v2)-0.0)<EPS)return true;
    return false;
}
bool isOrthogonal(const Vector &v1,const Vector &v2){
    if(fabs(dot(v1,v2)-0.0)<EPS)return true;
    return false;
}
Point projection( Point &p, Point &p1, Point &p2){
    Vector a=p-p1;
    Vector b=p2-p1;
    double r=dot(a,b);
    double pro_abs=r/b.norm();
    Vector res=b*pro_abs;
    return Point(res.x+p1.x,res.y+p1.y);
}
Point reflection(Point &p, Point &p1, Point &p2){
    Point pro=projection(p,p1,p2);
    Vector v=pro-p;
    v=v*2;
    return Point(v.x+p.x,v.y+p.y);
}
int ccw(Point &p, Point &p1, Point &p2){
    Vector a=p-p1;
    Vector b=p2-p1;
    if(cross(a,b)>0)return COUNTER_CLOCKWISE;
    if(cross(a,b)<0)return CLOCKWISE;
    if(dot(a,b)<0)return ONLINE_BACK;
    if(a.norm()>b.norm())return ONLINE_FRONT;
    return ON_SEGMENT;
}
bool intersect(segment &s1,segment &s2){
    if(ccw(s1.p1,s2.p1,s2.p2)*ccw(s1.p2,s2.p1,s2.p2)<=0 && ccw(s2.p1,s1.p1,s1.p2)*ccw(s2.p2,s1.p1,s1.p2)<=0)
        return true;
    return false;
}
double getDistanceSP(Point &p,segment &s){
    if(dot(p-s.p1,s.p2-s.p1)<0)return (p-s.p1).abs();
    if(dot(p-s.p2,s.p1-s.p2)<0)return (p-s.p2).abs();
    return fabs(cross(p-s.p1,s.p2-s.p1)/(s.p2-s.p1).abs());
}
double Distance(segment &s1,segment &s2){
    if(intersect(s1,s2))return 0;
    return min(min(getDistanceSP(s1.p1,s2),getDistanceSP(s1.p2,s2)),min(getDistanceSP(s2.p1,s1),getDistanceSP(s2.p2,s1)));
}
Point CrossPoint(segment &s1,segment &s2){
    Vector base =s2.p2-s2.p1;
    double d1=fabs(cross(base,s1.p1-s2.p1));
    double d2=fabs(cross(base,s1.p2-s2.p1));
    double t=d1/(d1+d2);
    return (s1.p2-s1.p1)*t+s1.p1;
}
pair<Point,Point> getCrossPoints(Circle &c,Line &l){
    Vector e = (l.p2-l.p1)/(l.p2-l.p1).abs();
    Point p=projection(c.c,l.p1,l.p2);
    double len=sqrt(c.r*c.r-(p-c.c).norm());
    return make_pair(p-e*len,p+e*len);
 }
pair<Point,Point> getCrossPoints(Circle &c1,Circle &c2){
    double d=(c1.c-c2.c).abs();
    double a=acos((c1.r*c1.r+d*d-c2.r*c2.r)/(2*c1.r*d));
    double t=atan2((c2.c-c1.c).y,(c2.c-c1.c).x);
    Point p1(c1.r*cos(t+a),c1.r*sin(t+a));
    Point p2(c1.r*cos(t-a),c1.r*sin(t-a));
    return make_pair(c1.c+p1,c1.c+p2);
}
//点的内包
int PPC(Point &p){
    int n=g.size();
    bool x=false;
    for(int i=0;i<n;i++)
    {
        Vector a=g[i]-p;
        Vector b=g[(i+1)%n]-p;
        if(fabs(cross(a,b)-0)<EPS && dot(a,b)<=0)return 1;
        if(a.y>b.y)swap(a,b);
        if(a.y<EPS && 0<b.y && cross(a,b)>0)x=!x;
    }
    return x?2:0;
}
int main()
{
    int n,q,x,y;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x>>y;
        Point p(x,y);
        g.push_back(p);
    }
    cin>>q;
    for(int i=0;i<q;i++)
    {
        cin>>x>>y;
        Point p(x,y);
        cout<<PPC(p)<<endl;
    }
    return 0;
}
