#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;
const double eps=1e-10;

//A Symmetric Point(AOJ)
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0081&lang=jp
//about 10min
//line構造体を作成し鏡映点を返す関数をつくった。具体的には正射影ベクトルを求めてから鏡映点を導いている。
//一個目の提出で明記し忘れたが, 下記サイトを参考にした。
//https://sen-comp.hatenablog.com/entry/2020/03/10/015751
//https://qiita.com/Reputeless/items/96226cfe1282a014b147

struct vec2{
    double x;
    double y;
    
    vec2()=default;
    vec2(double x_,double y_){
        x=x_;
        y=y_;
    }

    double length() const{//長さ
        return sqrt(x*x+y*y);
    }
    constexpr double lengthsquare() const{//長さの二乗
        return x*x+y*y;
    }
    constexpr double dot(const vec2& other) const{//内積
        return x*other.x+y*other.y;
    }
    constexpr double cross(const vec2& other) const{//外積
        return x*other.y-y*other.x;
    }
    double distancefrom(const vec2& other) const{//otherとの距離
        return (other-*this).length();
    }
    vec2 unitvector() const{//単位ベクトル
        return *this/length();
    }
    vec2 normalunitvector() const{//単位法線ベクトル
        return{-unitvector().y,unitvector().x};
    }
    vec2 rotation(double arg) const{//(0,0)を中心にarg回転
        double cs=cos(arg);double sn=sin(arg);
        return {x*cs-y*sn,x*sn+y*cs};
    }
    double angle() const{//(0,0)を中心としたときの偏角
        return atan2(y,x);
    }
    constexpr bool iszero() const{//原点と一致するか
        return x==0.0 && y==0.0;
    }
    
    vec2 operator+() const{
        return *this;
    }
    vec2 operator-() const{
        return {-x,-y};
    }
    vec2 operator+(const vec2& other) const{
        return {x+other.x,y+other.y};
    }
    vec2 operator-(const vec2& other) const{
        return {x-other.x,y-other.y};
    }
    vec2 operator*(double c) const{
        return {c*x,c*y};
    }
    vec2 operator/(double c) const{
        return {x/c,y/c};
    }
    vec2& operator+=(const vec2& other){
        x+=other.x;
        y+=other.y;
        return *this;
    }
    vec2& operator-=(const vec2& other){
        x-=other.x;
        y-=other.y;
        return *this;
    }
    vec2& operator*=(double c){
        x*=c;
        y*=c;
        return *this;
    }
    vec2& operator/=(double c){
        x/=c;
        y/=c;
        return *this;
    }
};

int sgn(const double a){
    return(a<-eps?-1:(a>eps?1:0));
}

inline vec2 operator*(double s,const vec2& v){
    return {s*v.x,s*v.y};
}
inline bool operator<(const vec2& a, const vec2& b){
    if(sgn(a.x-b.x)!=0)return sgn(a.x-b.x)<0;
    else return sgn(a.y-b.y)<0;
}
int isp(const vec2& a,const vec2& b,const vec2& c){
    //三点A,B,Cの位置関係を示す。全部異なっていることが前提条件。
    //ABから見てBCが左に曲がるなら1, 右に曲がるなら-1
    //ABC(CBA)の順で一直線上に並ぶなら2, ACB(BCA)の順なら0, BAC(CAB)の順なら-2

    int tmp=sgn((b-a).cross(c-a));
    if(tmp==1)return 1;
    else if(tmp==-1)return -1;
    else{
        if(sgn((b-a).dot(c-b))>0)return 2;
        else if(sgn((a-b).dot(c-a))>0)return -2;
        else return 0;
    }
}
int angletype(const vec2& a,const vec2& b,const vec2& c){//1:鋭角,2:直角,3:鈍角
    auto tmp=(a-b).dot(c-b);
    if(sgn(tmp)>0)return 0;
    else if(sgn(tmp)==0)return 1;
    else return 2;
}

struct line{
    vec2 sp,ep;//start poine,end poine
    
    line()=default;
    line(const vec2& b,const vec2& e){//二点を通る直線
        sp=b;
        ep=e;
    }
    line(const double a,const double b,const double c){//ax+by+c=0
        if(sgn(a)==0&&sgn(b)==0)assert(-1);//警告を出してプログラムを終了
        if(sgn(b)==0){
            sp=vec2(-c/a,0.0);
            ep=vec2(-c/a,1.0);
        }
        else{
            sp=vec2(0.0,-c/b);
            ep=vec2(1.0,-(a+c)/b);
        }
    }

    vec2 vec() const{//方向ベクトル
        return ep-sp;
    }
    vec2 countervec() const{
        return sp-ep;
    }
};

typedef line ray;//半直線
typedef line segment;//線分

vec2 error_val={(double)inf,(double)inf};

vec2 lineintersection(const line& l1,const line& l2){//直線の交点
    if(sgn(l1.vec().cross(l2.vec()))==0.0)return error_val;//交わらない場合
    vec2 tmp;
    tmp=l1.sp+l1.vec()*abs((l2.ep-l1.sp).cross(l2.vec())/l1.vec().cross(l2.vec()));
    return tmp;
}
pair<bool,vec2> segmentintersection(const segment& s1,const segment& s2){//線分の交点
    if(isp(s1.sp,s1.ep,s2.sp)*isp(s1.sp,s1.ep,s2.ep)<=0&&isp(s2.sp,s2.ep,s1.sp)*isp(s2.sp,s2.ep,s1.ep)<=0){
        if(s1.vec().cross(s2.vec())==0)return mp(true,error_val);//重なる場合
        else return mp(true,lineintersection(s1,s2));
    }
    return mp(false,error_val);
}
double pointlinedistance(const vec2& v,const line& l){//点と直線の距離
    return abs(l.vec().cross(v-l.sp)/l.vec().length());
}
double pointraydistance(const vec2& v,const ray& r){//点と半直線の距離
    if(sgn((v-r.sp).dot(r.vec()))<0)return r.sp.distancefrom(v);
    return pointlinedistance(v,r);
}
double pointsegmentdistance(const vec2& v,const segment& s){
    if(sgn(s.vec().dot(v-s.sp))<0||sgn(s.countervec().dot(v-s.ep))<0)return min(v.distancefrom(s.sp),v.distancefrom(s.ep));
    return pointlinedistance(v,s);
}
double segmentsegmentdistance(const segment& s1,const segment& s2){//線分間の距離
    if(segmentintersection(s1,s2).first)return 0;
    double tmp=pointsegmentdistance(s1.sp,s2);
    tmp=min(tmp,pointsegmentdistance(s1.ep,s2));
    tmp=min(tmp,pointsegmentdistance(s2.sp,s1));
    tmp=min(tmp,pointsegmentdistance(s2.ep,s1));
    return tmp;
}
vec2 projection(const vec2& v,const line& l){//正射影
    vec2 tmp;
    tmp=l.sp+l.vec().unitvector()*(v-l.sp).dot(l.vec())/l.vec().length();
    return tmp;
}
vec2 reflection(const vec2& v,const line& l){//鏡映(ある直線に対して与えられた点と対称な点を返す)
    vec2 tmp;
    tmp=v+2*(projection(v,l)-v);
    return tmp;
}

int main(){
    int n;cin>>n;
    vector<vec2> p(n+1);
    double x,y;
    set<int> point;
    rep(i,n){
        cin>>x>>y;
        p[i]=vec2(x,y);
        point.insert((int)y);
    }
    p[n]=p[0];
    double can;
    rep(i,120){
        if(!point.count(i)){
            can=(double)i;
            break;
        }
    }
    int q;cin>>q;
    vin ans(q);
    int sum,onlinepoint;bool online;
    rep(i,q){
        cin>>x>>y;
        segment s(vec2(x,y),vec2((double)10010,can));
        sum=0;onlinepoint=0;online=false;
        rep(j,n){
            segment tmp(p[j],p[j+1]);
            if(sgn(pointsegmentdistance(p[j],s))==0)onlinepoint++;
            if(sgn(pointsegmentdistance(s.sp,tmp)-0.0)==0){
                online=true;
                break;
            }
            if(segmentintersection(s,tmp).first)sum++;
        }
        if(online)ans[i]=1;
        else{
            if((sum-onlinepoint)%2)ans[i]=2;
            else ans[i]=0;
        }
    }
    rep(i,q)cout<<ans[i]<<endl;
}


Measured memory_bytes: 3216