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<bits/stdc++.h>
#define Re real()
#define Im imag()
using namespace std;

const double eps = 1e-9;
typedef complex<double> Point;
typedef Point Vector;
typedef vector<Point> Polygon;

Point P[50050], s;
int n, k, m;
vector<Point> qs;

bool cmp(Point a, Point b)
{
    if(fabs(a.Re - b.Re) < eps) return a.Im < b.Im;
    else return a.Re < b.Re;
}

double cross(const Point& a, const Point& b)
{
    return (conj(a) * b).Im;
}

double dot(const Point& a, const Point& b)
{
    return (conj(a) * b).Re;
}

int check(const Point& t)
{
    int cnt = 0;
    for(int i = 0; i < n; i++)
    {
        Vector v1 = P[i] - t, v2 = P[(i + 1) % n] - t;
        if(v1.Im > v2.Im) swap(v1, v2);
        if(v1.Im <= 0 && v2.Im > 0 && cross(v1, v2) < 0) cnt ^= 1;
        if(cross(v1, v2) == 0 && dot(v1, v2) <= 0) return 1;
    }
    return cnt ? 2 : 0;
}

int main()
{
    while(~scanf("%d", &n))
    {
        for(int i = 0; i < n; i++)
        {
            double tx, ty;
            scanf("%lf%lf", &tx, &ty);
            P[i] = complex<double>(tx, ty);
        }
        scanf("%d", &m);
        for(int i = 0; i < m; i++)
        {
            double tx, ty;
            scanf("%lf%lf", &tx, &ty);
            s = Point(tx, ty);
            printf("%d\n", check(s));
        }
    }
    return 0;
}

/*

5
0 0
2 0
2 2
0 2
1 1

4
0 0
3 1
3 3
0 3
16
1 1
2 1
1 2
2 2
3 1
3 2
0 3
0 2
2 0
4 1
-1 1
0 -1
1 4
3 4
4 3
-2 3

http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1128



#include <iostream>
#include <complex>
#include <vector>
using namespace std;

typedef complex<double> point;
double cross(const point& a, const point& b) {
    return imag(conj(a)*b);
}
double dot(const point& a, const point& b) {
    return real(conj(a)*b);
}

typedef vector<point> polygon;
enum { OUT, ON, IN };
int contains(const polygon& P, const point& p) {
    bool in = false;
    for (int i = 0; i < P.size(); ++i) {
        point a = P[i] - p, b = P[(i+1)%P.size()] - p;
        if (imag(a) > imag(b)) swap(a, b);
        if (imag(a) <= 0 && 0 < imag(b))
            if (cross(a, b) < 0) in = !in;
        if (cross(a, b) == 0 && dot(a, b) <= 0) return ON;
    }
    return in ? IN : OUT;
}

int main() {
    int n;
    while (cin >> n) {
        polygon pol(n);
        for (auto& p : pol) {
            int x, y;
            cin >> x >> y;
            p = point(x, y);
        }
        int q;
        cin >> q;
        for (int i = 0; i < q; i++) {
            int x, y;
            cin >> x >> y;
            cout << contains(pol, point(x, y)) << endl;
        }
    }
    return 0;
}

*/