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 <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 1e4;
const double eps = 1e-15;
const double inf = 1e10;
inline double sqr (double k) {return k * k;}
inline int sgn (double p) {
    if (fabs (p) < eps) return 0;
    if (p < 0) return -1;
    return 1;
}
struct point {
    double x, y;
    point () {}
    point (double _x, double _y) {
        x = _x, y = _y;
    }
    void input () {
        scanf ("%lf %lf", &x, &y);
    }
    bool operator == (point b) const {
        return sgn (x - b.x) == 0 && sgn (y - b.y) == 0;
    }
    point operator - (const point &b) const {
        return point (x - b.x, y - b.y);
    }
    double operator * (const point &b) const {
        return x * b.x + y * b.y;
    }
    double operator ^ (const point &b) const {
        return x * b.y - y * b.x;
    }
    double len () {
        return hypot (x, y);
    }
    double len2 () {
        return x * x + y * y;
    }
    double distance (point p) {
        return hypot (x - p.x, y - p.y);
    }
    point operator + (const point &b) const {
        return point (x + b.x, y + b.y);
    }
    point operator * (const double &b) const {
        return point (x * b, y * b);
    }
    point operator / (const double &b) const {
        return point (x / b, y / b);
    }
    double cross (point a, point b) {///叉积
        return (a - *this) ^ (b - *this);
    }
    double dot (point a, point b) {///点积
        return (a - *this) * (b - *this);
    }
    bool on_seg (point a, point b) {///点是否在线段ab上
        return sgn (cross (a, b)) == 0 && dot (a, b) <= 0;
    }
} ps[N];
///两线段是否相交
bool seg (point a, point b, point c, point d) {
    if (c.y > d.y) swap (c, d);
    if (c.on_seg (a, b)) return true;
    if (a.cross (b, d) * a.cross (b, c) < 0 && c.cross (d, b) * c.cross (d, a) < 0) return true;
    return false;
}
/// 点的投影是否在线段ab上
bool check (point p, point a, point b) {
    point x = b - a;
    double k = x.len ();
    double u = a.dot (p, b) / k;
    x = (x / k) * u;
    x = x + a;
    if (x.on_seg (a, b)) return true;
    return false;
}
int cmp (point a, point b) {
    if ((a ^ b) > 0) return true;
    return false;
}
int main () {
//    freopen ("in.txt", "r", stdin);
    int n, Q;
    cin >> n;
    for (int i = 1; i <= n; i++) ps[i].input ();
    ps[n + 1] = ps[1];
    ps[0] = ps[n];
    cin >> Q;
    while (Q --) {
        int ans = 0;
        point s, e, a, b;
        s.input ();
        e = point (inf, s.y);
        for (int i = 1; i <= n + 1; i++) if (s.on_seg (ps[i], ps[i - 1])) ans = 1;
        if (ans) {
            cout << 1 << endl;
            continue;
        }
        for (int i = 1; i <= n; i++) {
            if (seg (s, e, ps[i], ps[i - 1])) {
                if (sgn (ps[i].y - ps[i - 1].y) == 0) ans++;
//                cout << i << "*****";
                ans++;
            }

        }
//        cout << ans << endl;
        if (ans % 2 == 0) cout << 0 << endl;
        else cout << 2 << endl;
    }
    return 0;
}

