import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}


immutable real EPS = 1e-11;

struct Point {
    real x, y;
    Point opBinary(string op)(in Point p) const if (op == "+" || op == "-") {
        return Point(mixin("x" ~ op ~ "p.x"), mixin("y" ~ op ~ "p.y"));
    }
    Point opBinary(string op)(real k) const if (op == "*" || op == "/") {
        return Point(mixin("x" ~ op ~ "k"), mixin("y" ~ op ~ "k"));
    }
};
real dot(in Point a, in Point b) { return a.x * b.x + a.y * b.y; }
real cross(in Point a, in Point b) { return a.x * b.y - a.y * b.x; }
real norm(in Point a) { return sqrt(dot(a, a)); }
Point rot90(in Point p) { return Point(-p.y, p.x); }
real angle(in Point a) { return atan2(a.y, a.x); }

const int CW = -1;
const int CCW = 1;
int ccw(Point a, Point b, Point c){
    b = b - a; c = c - a;                                          
    if (cross(b, c) > EPS) return +1;      // a,b,c????????????????¨???¨???
    if (cross(b, c) < -EPS) return -1;     // a,b,c?????????????¨???¨???                       
    if (dot(b, c) < 0) return +2;          // c--a--b ??´???                       
    if (norm(b) < norm(c)) return -2;      // a--b--c ??´???                       
    return 0;                              // a--c--b ??´???
}

struct Segment {
    Point a, b;
};
bool contains(in Segment s, in Point p) {
    return ccw(s.a, s.b, p) == 0;
}

struct Polygon {
    Point[] vs;
}
bool intersects(in Segment s, in Segment t) {
    return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}
bool contains(in Polygon polygon, in Point p) { // ?????????p???????????´????????????
    auto vs = polygon.vs;
    int N = cast(int)vs.length;
    int next(int i) { return (i + 1) % N; }
    auto t = Segment(p, Point(1e7 + 7, 2e7 + 9));
    int count = 0;
    foreach (i; 0 .. N) {
        auto s = Segment(vs[i], vs[next(i)]);
        if (t.intersects(s)) {
            count++;
        }

    }
    return count % 2 == 1;
}

void main() {
    int N; readf("%d\n", &N);
    auto vs = new Point[N];
    foreach (ref v; vs) {
        readf("%s %s\n", &v.x, &v.y);
    }
    int Q; readf("%d\n", &Q);
    auto poly = Polygon(vs);
    foreach (q; 0 .. Q) {
        Point p; readf("%s %s\n", &p.x, &p.y);
        int f() {
            foreach (i, v; vs) {
                if (Segment(v, vs[(i + 1) % N]).contains(p)) return 1;
            }
            if (poly.contains(p)) {
                return 2;
            }
            return 0;
        }
        writeln(f());
    }
}