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

int dcmp(double x) {
    static double eps = 1e-8;
    return (x > eps) - (x < -eps);
}

struct vec{
    double x, y;

    vec(double _x=0, double _y=0)
        :x(_x), y(_y) {}

    vec operator- () const{ return vec(-x, -y); }
    
    vec operator+ (const vec& v) const{ return vec(x+v.x, y+v.y); }
    vec operator- (const vec& v) const{ return vec(x-v.x, y-v.y); }
    vec operator* (double c) const{ return vec(x*c, y*c); }
    vec operator/ (double c) const{ return vec(x/c, y/c); }

    double dot(const vec& v) const{ return x*v.x + y*v.y; }
    double cross(const vec& v) const{ return x*v.y - y*v.x; }

    double len2() const{ return x*x + y*y; }
    double len() const{ return sqrt(len2()); }
    
    vec& norm() { return *this = *this / len(); }
    vec& rot(double rad) {
        return  *this = vec(x*cos(rad) - y*sin(rad), x*sin(rad) + y*cos(rad));
    }

    bool operator< (const vec& v) const{
        return dcmp(x-v.x) < 0 || (dcmp(x-v.x)==0 && dcmp(y-v.y) < 0);
    }
};

struct line{
    vec u, v; // u + x*v

    line() {}
    line(vec _u, vec _v)
        :u(_u), v(_v) {}

    vec get(double x) {
        return u + v * x;
    }
};

line makeline(vec a, vec b) {
    return line(a, b - a);
}

bool on_left(line l, vec u) {
    return dcmp(l.v.cross(u - l.u)) > 0;
}

vec line_intersection(line a, line b) {
    return b.u + b.v * b.v.cross(b.u-a.u) / a.v.cross(b.v);
}

bool segment_intersection(vec a, vec b, vec c, vec d) {
    line x = line(a, b-a), y = line(c, d-c);
    return on_left(x, c) != on_left(x, d) && on_left(y, a) != on_left(y, b);
}

std::vector<vec> convex_hull(std::vector<vec> p) {
    std::sort(p.begin(), p.end());
    std::vector<vec> ch;
    for (size_t i = 0; i < p.size(); ++i) {
        while (ch.size() > 1 && on_left(makeline(ch[ch.size()-2], p[i]), ch[ch.size()-1]))
            ch.pop_back();
        ch.push_back(p[i]);
    }
    size_t k = ch.size();
    for (int i = p.size() - 2; i >= 0; --i) {
        while (ch.size() > k && on_left(makeline(ch[ch.size()-2], p[i]), ch[ch.size()-1]))
            ch.pop_back();
        ch.push_back(p[i]);
    }
    ch.pop_back();
    return ch;
}

std::pair<vec, vec> convex_diameter(const std::vector<vec> &p) {
    int xmax = 0, xmin = 0, n = p.size();
    for (int i = 1; i < n; ++i) {
        if (p[i].x > p[xmax].x) xmax = i;
        if (p[i].x < p[xmin].x) xmin = i;
    }
    
    int i = xmax, j = xmin;
    int u = xmax, v = xmin;
    double ans = (p[xmax] - p[xmin]).len2();
    
    do {
        if ((p[i] - p[(i + 1) % n]).cross(p[j] - p[(j + 1) % n]) < 0) i = (i + 1) % n;
        else j = (j + 1) % n;

        double dist = (p[i] - p[j]).len2();
        if (dist > ans) {
            ans = dist;
            u = i; v = j;
        }
    }while(i != xmax || j != xmin);
    return std::make_pair(p[u], p[v]);
}

double polygon_area(const std::vector<vec>& v) {
    double area = 0;
    for (size_t i = 0; i < v.size(); ++i)
        area += v[i].cross(v[(i + 1) % v.size()]);
    return area * 0.5;
}

int relation(const std::vector<vec>& p, const vec& v) {
    int ret = -1, n = p.size();
    for (int i = 0; i < n; ++i) {
        vec a = p[i] - v, b = p[(i + 1) % n] - v;
        if (a.y > b.y) std::swap(a, b);
        if (a.y <= 0 && 0 < b.y && a.cross(b) < 0)
            ret = -ret;
        if (a.cross(b) == 0 && a.dot(b) <= 0) return 0;
  }
  return ret;
}

// end template

int main() {
    std::vector<vec> v;
    int n; scanf("%d", &n);
    while (n--) {
        int x, y;
        scanf("%d%d", &x, &y);
        v.push_back(vec(x, y));
    }
    scanf("%d", &n);
    while (n--) {
        vec p;
        scanf("%lf%lf", &p.x, &p.y);
        printf("%d\n", relation(v, p)+1);
    }
    return 0;
}

