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 <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define EPS 1e-10
using namespace std;
typedef long long ll;
struct Point{
	double x,y;
	Point(double x = 0.0,double y = 0.0): x(x),y(y) {}
	Point operator + (Point p){
		return Point(x + p.x,y + p.y);
	}
	Point operator - (Point p){
		return Point(x - p.x,y - p.y);
	}
	Point operator * (double lambda){
		return Point(x * lambda,y * lambda);
	}
	Point operator / (double lambda){
		return Point(x / lambda,y / lambda);
	}
	Point neg(){//negative.
		return Point(-x,-y);
	}
	double norm(){
		return x * x + y * y;
	}
	double abs_(){
		return sqrt(norm());
	}
	bool operator == (const Point &p)const
	{
		return abs(x - p.x) < EPS && abs(y - p.y) < EPS;
	}
	bool operator < (const Point &p)const
	{
		if(abs(x - p.x) < EPS) return y < p.y;
		else return x < p.x;
	}
};
typedef Point Vector;
struct Segment{
	Point p1,p2;
	Segment(Point p1 = Point(),Point p2 = Point()): p1(p1),p2(p2) {}
};
typedef Segment Line;
struct Circle{
	Point c;
	double r;
	Circle(Point c = Point(),double r = 0.0): c(c),r(r) {}
};
typedef vector<Point> Polygon;
double dot(Vector a,Vector b){
	return a.x * b.x + a.y * b.y;
}
double det(Vector a,Vector b){
	return a.x * b.y - b.x * a.y;
}
Vector rot(Vector a,double theta){//rotate.
	double x1 = cos(theta) * a.x - sin(theta) * a.y;
	double y1 = sin(theta) * a.x + cos(theta) * a.y;
	return Point(x1,y1);
}
bool vertical(Line l1,Line l2){
	return abs(dot(l1.p2 - l1.p1,l2.p2 - l2.p1)) < EPS;
}
bool parallel(Line l1,Line l2){
	return abs(det(l1.p2 - l1.p1,l2.p2 - l2.p1)) < EPS;
}
Point proj(Point p,Line l){
	Vector a = l.p2 - l.p1;
	double r = dot(a,p - l.p1) / a.norm();
	return l.p1 + a * r;
}
Point ref(Point p,Line l){
	Point A = proj(p,l);
	return A + (A - p);
}
int ccw(Segment/*Directed Segment*/ s,Point p){//
	Vector a = s.p2 - s.p1,b = p - s.p1;
	if(det(a,b) > EPS) return 1;//COUNTER_CLOCKWISE
	else if(det(a,b) < -EPS) return -1;//CLOCKWISE
	else if(dot(a,b) < -EPS) return 2;//ONLINE_BACK
	else if(a.norm() < b.norm() - EPS) return -2;//ONLINE_FRONT
	else return 0;//ON_SEGMENT
}
bool intersect(Segment s1,Segment s2){
	return ccw(s1,s2.p1) * ccw(s1,s2.p2) <= 0 && ccw(s2,s1.p1) * ccw(s2,s1.p2) <= 0;
}
double disSP(Segment s,Point p){
	Vector a = s.p2 - s.p1;
	if(dot(a,p - s.p1) < EPS) return (p - s.p1).abs_();
	if(dot(a.neg(),p - s.p2) < EPS) return (p - s.p2).abs_();
	return abs(det(a,p - s.p1) / a.abs_());
}
double disSS(Segment s1,Segment s2){
	if(intersect(s1,s2)) return 0;
	return min(min(disSP(s1,s2.p1),disSP(s1,s2.p2)),min(disSP(s2,s1.p1),disSP(s2,s1.p2)));
}
Point crossSS(Segment s1,Segment s2){//make sure s1 intersect s2!
	Vector a = s2.p2 - s2.p1;
	double d1 = abs(det(a,s1.p1 - s2.p1));
	double d2 = abs(det(a,s1.p2 - s2.p1));
	return s1.p1 + (s1.p2 - s1.p1) * (d1 / (d1 + d2));
}
vector <Point> crossCL(Circle o,Line l){//make sure crossing.
	Point A = proj(o.c,l);
	Vector a = l.p2 - l.p1, e = a / a.abs_();
	double AP = sqrt(o.r * o.r - (A - o.c).norm());
	vector <Point> res;
	res.push_back(A + e * AP);
	res.push_back(A - e * AP);
	return res;
}
vector <Point> crossCC(Circle o1,Circle o2){//make sure crossing.
	Vector a = o2.c - o1.c;
	double alpha = acos((o1.r * o1.r + a.norm() - o2.r * o2.r) / (2 * o1.r * a.abs_()));
	Vector b = a / a.abs_() * o1.r;
	vector <Point> res;
	res.push_back(o1.c + rot(b,alpha));
	res.push_back(o1.c + rot(b,-alpha));
	return res;
}
int pointInPolygon(Point p,Polygon po){
	int n = po.size();
	int in = 0;
	for(int i=0;i<n;i++){
		Point g1 = po[i],g2 = po[(i + 1) % n];
		Vector a = g1 - p,b = g2 - p;
		if(abs(det(a,b)) < EPS && dot(a,b) < EPS) return -1;//on-edge.
		if(a.y > b.y) swap(a,b);
		if(a.y < EPS && EPS < b.y && det(a,b) > EPS) in ^= 1;
	}
	return in;//1: in,0: out.
}
int main(){
	int n;
	scanf("%d",&n);
	Polygon po(n);
	for(int i=0;i<n;i++) scanf("%lf%lf",&po[i].x,&po[i].y);
	Point p;
	int q;
	scanf("%d",&q);
	while(q--){
		scanf("%lf%lf",&p.x,&p.y);
		int res = pointInPolygon(p,po);
		if(res == -1) puts("1");
		else if(res == 1) puts("2");
		else puts("0");
	}
	return 0;
}

