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 For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef double db;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

namespace Geometry{
	const db eps = 1e-9;
	struct point{
		db x,y;
		inline point operator + (const point &p){return (point){x+p.x,y+p.y};}
		inline point operator - (const point &p){return (point){x-p.x,y-p.y};}
		inline db operator * (const point &p){return x*p.x+y*p.y;}
		inline point operator / (const db &v){return (point){x/v,y/v};}
		inline point operator * (const db &v){return (point){x*v,y*v};}
	};
	typedef point vec;
	inline db dot(vec a,vec b){return a.x*b.x+a.y*b.y;}
	inline db sqr(db x){return x*x;}
	inline db dis(point a,point b){return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));}
	inline db dis2(point a,point b){return sqr(a.x-b.x)+sqr(a.y-b.y);}
	inline db cross(vec a,vec b){return a.x*b.y-a.y*b.x;}
	struct line{
		point a,b;
	};
	inline point projection(point A,line b){
		point B=b.a,C=b.b;
		vec BA=A-B,BC=C-B,BD=BC*(BA*BC/dis2(B,C));
		return B+BD;
	}
	inline point reflection(point A,line b){
		point D=projection(A,b);
		return (point){D.x*2-A.x,D.y*2-A.y};
	}
	inline int Counter_Clockwise(point A,line b){
		point B=b.a,C=b.b;
		db f1=cross(C-B,A-B);
		if (fabs(f1)>eps) return (f1<0?2:1);
		db f2=(C-B)*(A-B);
		if (f2<0) return 3;
		return dis(B,C)<dis(A,B)?4:5;
	}
	inline int checkline(line a,line b){
		vec A=a.b-a.a,B=b.b-b.a;
		db f1=A*B;
		if (fabs(f1)<=eps) return 1;
		return dis(a.a,a.b)*dis(b.a,b.b)-fabs(f1)<=eps?2:0;
	}
	inline bool checkseg(line a,line b){
		point A=a.a,B=a.b,C=b.a,D=b.b;
		if (max(A.x,B.x)<min(C.x,D.x)) return 0;
		if (min(A.x,B.x)>max(C.x,D.x)) return 0;
		if (max(A.y,B.y)<min(C.y,D.y)) return 0;
		if (min(A.y,B.y)>max(C.y,D.y)) return 0;
		db s=cross(B-A,C-A),h=cross(B-A,D-A);
		if (s*h>=eps) return 0;
		db i=cross(D-C,A-C),t=cross(D-C,B-C);
		return i*t<=eps;
	}
	inline point crosspoint(line a,line b){
		point A=a.a,B=a.b,C=b.a,D=b.b;
		db s1=fabs(cross(B-A,C-A)),s2=fabs(cross(B-A,D-A));
		vec CO=(D-C)*(s1/(s1+s2));
		return C+CO;
	}
	inline db dis(point	A,line b){
		point B=b.a,C=b.b,D=projection(A,b);
		int tmp=Counter_Clockwise(D,b);
		if (tmp==3) return dis(B,A);
		if (tmp==4) return dis(C,A);
		if (tmp==5) return dis(D,A);
	}
	inline db dis(line a,line b){
		if (checkseg(a,b)) return 0;
		db s=dis(a.a,b),h=dis(a.b,b),i=dis(b.a,a),t=dis(b.b,a);
		return min({s,h,i,t});
	}
	typedef vector<point> polygon;
	inline db S(polygon v){
		db s=cross(v.back(),v[0]);
		For(i,0,siz(v)-2) s+=cross(v[i],v[i+1]);
		return s/2;
	}
	inline bool check(polygon v){
		int n=siz(v),f=(cross(v[n-1]-v[n-2],v[0]-v[n-1])>=-eps);
		For(i,1,n-2) if ((cross(v[i]-v[i-1],v[i+1]-v[i])>=-eps)!=f) return 0;
		return 1;
	}
	inline int check(point a,polygon v){
		db k=sqrt(23);point b=(point){a.x+100000000,a.y+k*100000000};
		int n=siz(v);bool f=0;
		For(i,0,n-1){
			if (Counter_Clockwise(a,(line){v[i],v[(i+1)%n]})==5) return 1;
			if (checkseg((line){v[i],v[(i+1)%n]},(line){a,b})) f^=1;
		}
		return !f?0:2;
	}
};
using namespace Geometry;

int main(){
	int n=read();polygon v(n);
	FOR(i,0,n) scanf("%lf%lf",&v[i].x,&v[i].y);
	int T=read();
	while (T--){
		point a;scanf("%lf%lf",&a.x,&a.y);
		printf("%d\n",check(a,v));
	}
}
