#include<bits/stdc++.h>

using namespace std;

// Can't use x and y for first and second
#define x real()
#define y imag()
#define cpt const Pt&
//#define Pt Pt//const Pt&

const double EPS = 1e-9;
const double pi=acos(-1);
bool dequal(double a,double b) {return abs(a-b)<EPS;}
enum Orientation {CCW, CW, CNEITHER};


//using namespace std;
typedef complex<double> cpx;

struct Pt : public cpx {
    Pt() = default;
	using cpx::cpx;
	Pt(cpx a) : cpx(a) {}
    double& x const {
        return (double&)*this;
    }
    double& y const {
        return ((double*)this)[1];
    }

	bool operator ==(cpt b) const {return abs(*this-b) < EPS; }
	bool operator <(cpt b) const {return x<b.x || (x==b.x && y<b.y); }
	//by x first then break ties with y
};

//Allow points to be read in by input streams
istream& operator >>(istream& is, Pt& p) {
	return is >> p.x >> p.y;
}

double dot(cpt a, cpt b) {return (conj(a) * b).x;}// Dot product
double det(cpt a, cpt b) {return (conj(a) * b).y;}//Determinant/"Cross Product"
double angle(cpt a, cpt b) {return arg(b - a);}// [-pi,pi] a to b with x axis
double angle (cpt a, cpt b, cpt c) {return arg((a-b)/(c-b));}//[-pi,pi]
//double slope(cpt a, cpt b) {return tan(arg(b - a));}// m for line segment (a,b)
double slope(cpt a, cpt b) {return (b.y-a.y)/(b.x-a.x);}

Pt rotate(cpt a, double theta) {return a * polar(1.0, theta);}//anticlockwise
//around p by theta anticlockwise
Pt rotate(cpt a, cpt p, double theta) {return rotate(a - p,theta) + p;}
Pt project(cpt p, cpt v) {return v * dot(p, v) / norm(v);}// p onto v
Pt project(cpt p, cpt a, cpt b) {return a+project(p-a,b-a);}//p onto line (a,b)
//reflect p across the line (a,b)
Pt reflect(cpt p, cpt a, cpt b) {return a + conj((p - a) / (b - a)) * (b - a);}

//bool colinear(Pt a, Pt b, Pt c) {return dequal(det(b-a,c-b),0);}

// Orientation test (1 anticlockwise, -1 clockwise, 0 colinear)
int orient(cpt a, cpt b, cpt c) {
	double d=det(b-a,c-b);
	return d>EPS?1:d<-EPS?-1:0;
}

// Point on line segment (including endpoints)
bool ptonseg(cpt a, cpt b, cpt p) {
	Pt u=b-a,v=p-a;
	return a==p || b==p ||
		((0 < dot(u,v) && dot(u,v) < norm(u)) && dequal(det(u,v),0));
}

// Signed area of polygon
// Positive for anticlockwise orientation
double polygonarea(const vector<Pt>& p) {
	double r=0;
	int n=p.size();
	for (int j=0,i=n-1;j<n;i=j++) r+=det(p[i],p[j]);
	return r/2;
}

// Convex hull O(NlogN)
// if all points are colinear the middle points come up twice forwards and
// backwards e.g. a-b-c-d becomes a-b-c-d-c-b
// To remove colinear points change <-EPS and >EPS to <EPS and >-EPS.
vector<Pt> convexhull(vector<Pt> p) {
  sort(p.begin(),p.end()); p.resize(unique(p.begin(),p.end())-p.begin());
  int l=0,u=0;
  vector<Pt> L(p),U(p);
  if (p.size()<=2) return p;
  for (Pt& i:p) {
    while (l>1 && det(i-L[l-1],L[l-2]-i)<-EPS) l--;
    while (u>1 && det(i-U[u-1],U[u-2]-i)>EPS) u--;
    L[l++]=U[u++]=i;
  }
  L.resize(l+u-2);
  copy(U.rend()-u+1,U.rend()-1,L.begin()+l);

  return L;
}

//Point in polygon test O(N)
//Returns:
// 0 if not in polygon
// 1 if on boundary
// 2 if in interior
int ptinpoly(const vector<Pt>& p, cpt q) {
	int n=p.size();
	int i,j,r=0;
	for (j=0,i=n-1;j<n;i=j++) { //that trick to avoid modding
		if (ptonseg(p[i],p[j],q)) return 1;
		if (((p[i].y <= q.y && q.y < p[j].y)
			|| (p[j].y <= q.y && q.y < p[i].y))
			&& q.x < (p[j].x-p[i].x) * (q.y-p[i].y)/(p[j].y-p[i].y) + p[i].x)
			r^=2;
	}
	return r;
}

Pt solve(cpt a, cpt b, cpt v) {// solves [a b]x==v with Cramer's rule.
	return Pt(det(v,b)/det(a,b),det(a,v)/det(a,b));
}

//Intersection of 2 line segments. Divides by 0 if they are parallel.
//Returns {nan,nan} if they don't intersect.
//Uncomment if statements below to get infinite lines.
Pt intersectline(Pt a, Pt b, Pt p, Pt q) {
	Pt ab=b-a,qp=p-q,ap=p-a;
	double s=det(ap,qp)/det(ab,qp),t=det(ab,ap)/det(ab,qp);
	//double s,t;
	//tie(s,t)=solve(b-a,p-q,p-a);
	//a+t(b-a)=p+s(q-p)
	
	//Can also just use ptonseg.
	if (-EPS<s && s<1+EPS //Answer is on ab
		&& -EPS<t && t<1+EPS) //Answer is on pq 
		return a+s*(b-a);
	return Pt(NAN,NAN);
}

//Distance between infinite line and point.
double distlinept(cpt a, cpt b, cpt p) {
	return abs(det(b-a,p-a)/abs(b-a));
}

//Distance between finite line and point
double distfinitelinept(Pt a, Pt b, Pt p) {
	b-=a;p-=a;
	double sp=(p/b).x;//dot(b,p)/norm(b);
	Pt closest;
	if (sp>=0) {
		if (sp>1) closest=b;
		else closest=sp*b;
	}
	return abs(closest-p); // Note that actual closest Pt on line is closest + a
}



//Are lines parallel?
bool arepara(cpt a, cpt b, cpt p, cpt q) {
	return dequal(det(b-a,q-p),0);
}

//Distance between 2 finite lines
double distfinitelineline(Pt a,Pt b,Pt p,Pt q) {
	if (!arepara(a,b,p,q) && std::isnan(intersectline(a,b,p,q).x)) return 0;
	
	/*if (arepara(a,b,p,q)) {
		b-=a;p-=a;q-=a;
		double sp=dot(b,p)/norm(b);
		if (0<sp && sp<1) return det(b,p)/abs(b);
	}*/
	
	return min({
			distfinitelinept(a,b,p),
			distfinitelinept(a,b,q),
			distfinitelinept(p,q,a),
			distfinitelinept(p,q,b)
	});
}

//This is kind of unnecessary
double distpara(Pt a, Pt b, Pt p, Pt q) {
	return distlinept(a,b,p);
}




/*
// Intersection of lines (a,b) and (p,q)
Pt intersection(Pt a, Pt b, Pt p, Pt q) {		
  double c1 = cross(p - a, b - a), c2 = cross(q - a, b - a);
  return (c1 * q - c2 * p) / (c1 - c2); // undefined if parallel
}
*/

namespace Test {
	void solve() {
		Pt a{3,2};
		Pt b(2,-7);
		vector<Pt> aa{{1,2},{3,4},{5,6}};
		//for (Pt p:convexhull(aa)) cout << p << endl;
		//cout << endl;


		//cout << a + b << endl;
		//cout << a - b << endl;

		Pt c(0,0);
		Pt d(1e-10, 1e-10);

		//cout << (a == b) << endl;
		//cout << (c == d) << endl;

		cout << "dot det\n";
		//cout << dot(a,b) << endl;
		//cout << det(a,b) << endl;
		//cout << rotate({1,0},pi/2) << endl;


		a.x=0;
		//cout << a.x << endl;

		//cout << ((double*)a)[0] << endl;
		//a[0]=50;
		//cout << a[0] << endl;

		//cout << intersectline({10,1},{11,2},{11,1},{10,2}) << endl;
		cout << intersectline({10,1},{9,0},{11,1},{10,2}) << endl;

		cout << ptonseg({3,2},{5,4},{4,3}) << endl;
		cout << ptonseg({3,2},{5,4},{3,4}) << endl;
		cout << ptonseg({3,2},{5,4},{5,2}) << endl;

		vector<Pt> poly{{0,0},{2,2},{0,1}};
		cout << ptinpoly(poly,{1,1}) << endl;
		cout << ptinpoly(poly,{2,2}) << endl;
		cout << ptinpoly(poly,{-1,2}) << endl;
		cout << ptinpoly(poly,{4,3}) << endl;
		cout << ptinpoly(poly,{0.5,.75}) << endl;
	}
}


namespace UVA_920 {
	void solve() {
		int T,n;
		cin >> T;
		cout << fixed << setprecision(2);
		while (T--) {
			cin >> n;
			vector<Pt> pts(n);
			for (Pt &p:pts) cin >> p;
			sort(pts.rbegin(),pts.rend());
			double ans=0,M=0;
			for (int i=1;i<n;i++) {
				Pt cept=intersectline(pts[i-1],pts[i],{-1,M},{30001,M});
				if (pts[i].y>M) ans+=abs(cept-pts[i]);
				M=max(M,pts[i].y);
			}

			cout << ans << '\n';
		}
	}
}

namespace UVA_10263 {
	Pt distfinitelinept(Pt a, Pt b, Pt p) {
		b-=a;p-=a;
		double sp=(p/b).x;//dot(b,p)/norm(b);
		Pt closest;
		if (sp>=0) {
			if (sp>1) closest=b;
			else closest=sp*b;
		}
		return closest+a;
	}
	void solve() {
		cout << fixed << setprecision(4);
		Pt M;
		int n;
		while (cin >> M) {
			Pt ans(1e100,1e100);
			cin >> n;
			vector<Pt> pts(n+1);
			for (Pt &p:pts) cin >> p;
			for (int i=1;i<=n;i++) {
				Pt cur=UVA_10263::distfinitelinept(pts[i-1],pts[i],M);
				if (abs(cur-M)<abs(ans-M)) ans=cur;
			}
			cout << ans.x << '\n' << ans.y << '\n';
		}
	}
}

namespace UVA_10927 {
	double safearg(cpt a) {
		double ag=arg(a);
		if (dequal(ag,-pi)) return pi;
		return ag;
	}
	bool less(cpt a,cpt b) {
		double ag=safearg(a),bg=safearg(b);
		return ag<bg-EPS || (dequal(ag,bg) && abs(a)<abs(b));
	}

#define X first
#define Y second

	typedef pair<Pt,int> Pole;

	void solve() {
		int n;
		int cas=1;
		cout << fixed  << setprecision(0);
		while (cin >> n && n) {
			vector<Pole> poles(n);
			for (Pole &pol:poles) {
				cin >> pol.X >> pol.Y;
			}
			sort(poles.begin(),poles.end(), [](const Pole& a,const Pole& b) {return less(a.X,b.X);});

			vector<Pt> ans;

			for (int i=0,j=0;i<n;i=j) {
				for (;j<n && dequal(safearg(poles[i].X),safearg(poles[j].X));j++);
				int M=-1;
				for (int k=i;k<j;k++) {
					if (poles[k].Y<=M) ans.push_back(poles[k].X);
					M=max(M,poles[k].Y);
				}
			}

			cout << "Data set " << cas++ << ":\n";
			if (ans.empty()) {
				cout << "All the lights are visible.\n";
			}
			else {
				sort(ans.begin(),ans.end());
				cout << "Some lights are not visible:\n";
				for (int i=0;i<ans.size();i++) {
					cout << "x = " << ans[i].x << ", y = " << ans[i].y;
					if (i+1==ans.size()) cout << ".\n";
					else cout << ";\n";
				}
			}
		}
	}

#undef X
#undef Y
}

namespace UVA_378 {
	Pt intersectline(Pt a, Pt b, Pt p, Pt q) {
		Pt ab=b-a,qp=p-q,ap=p-a;
		double s=det(ap,qp)/det(ab,qp),t=det(ab,ap)/det(ab,qp);
		//double s,t;
		//tie(s,t)=solve(b-a,p-q,p-a);
		//a+t(b-a)=p+s(q-p)

		//Can also just use ptonseg.
		//if (-EPS<s && s<1+EPS //Answer is on ab
		//	&& -EPS<t && t<1+EPS) //Answer is on pq 
		return a+s*(b-a);
		return Pt(NAN,NAN);
	}

	void solve() {
		int N;
		cin >> N;
		cout << "INTERSECTING LINES OUTPUT\n" << fixed << setprecision(2);
		while (N--) {
			Pt a,b,c,d;
			cin >> a >> b >> c >> d;
			if (arepara(a,b,c,d)) {
				if (distlinept(a,b,c)>EPS) cout << "NONE\n";
				else cout << "LINE\n";
			}
			else {
				Pt ans=UVA_378::intersectline(a,b,c,d);
				cout << "POINT " << ans.x << ' ' << ans.y << '\n';
			}
		}
		cout << "END OF OUTPUT\n";
	}
}

namespace UVA_191 {
	void solve() {
		int n;
		cin >> n;
		while (n--) {
			Pt a,b,c,d;
			cin >> a >> b >> c >> d;
			if (c.x>d.x) swap(c.x,d.x);
			if (c.y>d.y) swap(c.y,d.y);
			if ((c.x-EPS<a.x && a.x<d.x+EPS && c.y-EPS<a.y && a.y<d.y+EPS)
					|| !std::isnan(intersectline(a,b,{c.x,c.y},{c.x,d.y}).x)
					|| !std::isnan(intersectline(a,b,{c.x,c.y},{d.x,c.y}).x)
					|| !std::isnan(intersectline(a,b,{c.x,d.y},{d.x,d.y}).x)
					|| !std::isnan(intersectline(a,b,{d.x,c.y},{d.x,d.y}).x))
				cout << "T\n";
			else cout << "F\n";
		}
	}
}

namespace AIZU_CGL_3_C {
	void solve() {
		int n;
		cin >> n;
		vector<Pt> poly(n);
		for (Pt &p:poly) cin >> p;
		int q;
		cin >> q;
		while (q--) {
			Pt p;
			cin >> p;
			cout << ptinpoly(poly,p) << '\n';
		}
	}
}


//namespace UVA_634 {


int main() {
	
	//Test::solve();
	//UVA_920::solve();
	//UVA_10263::solve();
	//UVA_10927::solve(); // Ensure EPS=1e-10
	//UVA_378::solve();
	//UVA_191::solve();
	AIZU_CGL_3_C::solve();
}

Measured memory_bytes: 3292