#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
using namespace std;
const double EPS = 1e-7;
const double INF = 1e12;
struct Vec {
    double x,y;
    Vec() {}
    Vec(double x, double y) { 
        this->x = x, this->y = y; 
    }
    void read() { 
        scanf("%lf %lf", &x, &y); 
    }
    void prt() {
        printf("%.9f %.9f\n", x, y); 
    }
    double len() { 
        return sqrt(x * x + y * y); 
    }
    double len2() { 
        return x * x + y * y; 
    }
    
    Vec operator +(const Vec& o)const { 
        return Vec(x + o.x, y + o.y); 
    }
    Vec operator -(const Vec& o)const { 
        return Vec(x - o.x, y - o.y); 
    }
    Vec operator *(const double& k)const { 
        return Vec(k * x, k * y); 
    }
    double operator *(const Vec& o)const {
        return x * o.x + y * o.y; 
    }
    double operator ^(const Vec& o)const {
        return x * o.y - y * o.x; 
    }
    Vec rotate(double ang){ 
        return Vec(x * cos(ang) - y * sin(ang), x * sin(ang) + y * cos(ang)); 
    }
    Vec change(double l) { 
        if(len() < EPS) return *this; 
        return (*this) * (l/len()); 
    }
};


struct Line {
    Vec A1, A2;
    Line() {}
    Line(Vec A1, Vec A2) {
        this->A1 = A1, this->A2 = A2;
    }
    double len() {
        return (A2-A1).len();
    }
    double Len2() {
        return (A2-A1).len2();
    }
};


double disToLine(Vec P, Line L) {
    return abs((P-L.A1)^(L.A2-L.A1)) / L.len();
}
Vec projection(Vec P, Line L) {
    double shadowLen = (P - L.A1) * (L.A2 - L.A1);
    return L.A1 + (L.A2-L.A1).change(shadowLen);
}

bool onseg(Vec P, Line L) {
    if(disToLine(P, L) > EPS) return 0;
    return (P-L.A1) * (P-L.A2) <= 0;
}

Vec Lineintersect(Line L1, Line L2) {
    // 0 ~ (L2.A1 - L1.A1) ^ (L2.A2 - L1.A1);
    // 1 ~ (L2.A1 - L1.A2) ^ (L2.A2 - L1.A2);
    double F0 = (L2.A1 - L1.A1) ^ (L2.A2 - L1.A1);
    double F1 = (L2.A1 - L1.A2) ^ (L2.A2 - L1.A2);
    if (abs(F1 - F0) < EPS) return Vec(INF, INF);
    return L1.A1 + (L1.A2 - L1.A1) * (- F0 / (F1 - F0));
}

Vec Segintersect(Line L1, Line L2) {
    Vec P = Lineintersect(L1, L2);
    if (P.x == INF) return P;
    if (onseg(P, L1) && onseg(P, L2)) return P;
    return Vec(INF, INF);
}

bool disToSeg(Vec P, Line L) {
    double ans = min((P-L.A1).len(), (P-L.A2).len());
    ans = min(ans, (P - projection(P,L)).len());
    return ans;
}

struct Polygon {
    int n; 
    vector<Vec> v;
    void read() {
        scanf("%d", &n);
        v.resize(2*n);
        for(int i=0;i<n;i++){
            Vec tmp; tmp.read();
            v[i] = v[i+n] = tmp;
        }
    }
    double getArea() {
        double ans=0;
        for(int i=0;i<n;i++){
            ans=ans+(v[i]^v[i+1]);
        }
        return abs(ans/2);
    }
    bool isConvex() {
        for(int i=0;i<n;i++){
            if( ((v[i+1]-v[i])^(v[i+2]-v[i+1])) < 0 )
                return 0;
        }
        return 1;
    }
    int containVec(Vec P) {
        int flag = 0;
        for(int i=0;i<n;i++) {
            if (onseg(P,Line(v[i], v[i+1]))) return 1;
            Vec Q = Lineintersect(Line(P,Vec(P.x+1,P.y)),Line(v[i],v[i+1]));
            if (Q.x == INF) continue;
            if (onseg(Q, Line(v[i], v[i+1]))) {
                if (abs(Q.y - min(v[i].y, v[i+1].y)) > EPS && Q.x >= P.x)
                    flag ^= 1;
            }
        }
        return flag?2:0;
    }
} poly;

int main(){
    poly.read();
    int q; scanf("%d", &q);
    while(q--) {
        Vec P; P.read();
        printf("%d\n", poly.containVec(P));
    }
}



Measured memory_bytes: 3244