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 <complex>
#include <cmath>
#include <algorithm>
#include <vector>

template <class T>
inline T sq(T x) { return x * x; }

using Real = long double;
using Point = std::complex<Real>;
using Segment = std::pair<Point, Point>;
using Polygon = std::vector<Point>;

const Real EPS = 1e-10;
const Point origin(0, 0);

// 宇宙船演算子
inline Real compare(Real a, Real b) {
    if (std::abs(a - b) < EPS) return 0;
    return a - b > 0 ? 1 : -1;
}

inline Real dist(Point a, Point b) {
    return std::abs(a - b);
}

inline Real length(Segment s) {
    return dist(s.first, s.second);
}

// inner product
inline Real dot(Point x, Point y) {
    return std::real(std::conj(x) * (y));
}

// outer product
inline Real cross(Point x, Point y) {
    return std::imag(std::conj(x) * (y));
}

// lに対するxの正射影
Point proj(Segment s, Point p) {
    Real ratio = dot(s.second - s.first, p - s.first) / sq(length(s));
    return s.first + (s.second - s.first) * ratio;
}

// lを軸としてxに対称な点
Point refl(Segment s, Point p) {
    Point t = proj(s, p);
    return t + (t - p);
}

// lに対するpの位置
// 0: on segment
// 1: counter clockwise  -1: clockwise
// 2: online front       -2: online back
int side(Segment s, Point p) {
    Real c = cross(s.second - s.first, p - s.first);
    if (compare(c, 0) != 0) return compare(c, 0);

    Real d = dot(s.second - s.first, p - s.first);
    if (compare(d, 0) < 0) return -2;

    return (compare(length(Segment(s.first, p)), length(s)) > 0 ? 2 : 0);
}

inline bool isorthogonal(Segment s1, Segment s2) {
    return compare(dot(s1.second - s1.first, s2.second - s2.first), 0) == 0;
}

inline bool isparallel(Segment s1, Segment s2) {
    return compare(cross(s1.second - s1.first, s2.second - s2.first), 0) == 0;
}

inline bool intersect(Segment s1, Segment s2) {
    return (side(s1, s2.first) * side(s1, s2.second) <= 0) &&
           (side(s2, s1.first) * side(s2, s1.second) <= 0);
}

Point intersection(Segment s1, Segment s2) {
    Real c1 = cross(s2.second - s2.first, s1.second - s1.first);
    Real c2 = cross(s2.second - s2.first, s1.first - s2.first);
    return s1.first + (s1.second - s1.first) * (-c2 / c1);
}

// distanceのオーバーロード
Real dist(Segment s, Point p) {
    Point t = proj(s, p);
    if (side(s, t) == 0) return dist(p, t);
    return std::min(dist(p, s.first), dist(p, s.second));
}

Real dist(Segment s1, Segment s2) {
    if (intersect(s1, s2)) return 0;
    return std::min({dist(s1, s2.first),
                     dist(s1, s2.second),
                     dist(s2, s1.first),
                     dist(s2, s1.second)});
}

// signed area
inline Real triangle(Point a, Point b, Point c) {
    return cross(b - a, c - a) / 2;
}

Real area(const Polygon& g) {
    Real S = 0;
    for (int i = 0; i < g.size(); ++i) {
        S += triangle(origin, g[i], g[(i + 1) % g.size()]);
    }
    return S;
}

bool isconvex(const Polygon& g) {
    for (int i = 0; i < g.size(); ++i) {
        if (side(Segment(g[i], g[(i + 1) % g.size()]),
                 g[(i + 2) % g.size()]) == -1) return false;
    }
    return true;
}
// 0: out  1: on  2: in
int contain(const Polygon& g, Point p) {
    bool in = false;
    for (int i = 0; i < g.size(); ++i) {
        if (side(Segment(g[i], g[(i + 1) % g.size()]), p) == 0) return 1;

        Point a = g[i] - p, b = g[(i + 1) % g.size()] - p;
        if (compare(a.imag(), b.imag()) > 0) std::swap(a, b);
        if (compare(a.imag(), 0) <= 0 &&
            compare(b.imag(), 0) > 0 &&
            compare(cross(a, b), 0) < 0) in = !in;
    }
    return in ? 2 : 0;
}


#include <iostream>
#include <iomanip>

using namespace std;

int main() {
    int N;
    cin >> N;

    Polygon g(N);
    for (auto& p : g) {
        Real x, y;
        cin >> x >> y;
        p = Point(x, y);
    }

    int Q;
    cin >> Q;
    for (int q = 0; q < Q; ++q) {
        Real x, y;
        cin >> x >> y;
        cout << contain(g, Point(x, y)) << endl;
    }
    return 0;
}

