import ru.ifmo.validate.*;

import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.lang.*;

public class Validate implements Validator {

    final int maxN = 2000;
    final int maxM = 2000;
    final int maxC = 1000000;


    public void validate(ValidatingScanner inf) {
        int n;
        n = inf.nextInt(1, maxN);
        inf.eoln();
        int[] x = new int[n];
        int[] y = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = inf.nextInt(-maxC, maxC);
            y[i] = inf.nextInt(-maxC, maxC);
            inf.eoln();
        }
        for (int i = 0; i < n; i++){
        	int dx1 = (x[(i + 1) % n] - x[(i + 0) % n]);
        	int dx2 = (x[(i + 2) % n] - x[(i + 1) % n]);
        	int dy1 = (y[(i + 1) % n] - y[(i + 0) % n]);
        	int dy2 = (y[(i + 2) % n] - y[(i + 1) % n]);
        	if ((long)(dx1) * dy2 - (long)(dx2) * dy1 == 0)
                throw new RuntimeException(String.format("Points #%d,#%d,#%d are on one line", i, (i+1) % n, (i + 2) % n));
        	     
        }
        for (int i = 0; i < n; i++)
            for (int j = i + 2; j < n; j++)
                if (!(i == 0 && j == n - 1) && SharedGeom.checkSegmentIntersection(
                        x[i], y[i], x[(i + 1) % n], y[(i + 1) % n],
                        x[j], y[j], x[(j + 1) % n], y[(j + 1) % n]
                ))
                    throw new RuntimeException(
                            String.format("Polygon have self-intersections : [(%d, %d),(%d,%d)] and [(%d, %d),(%d,%d)]",
                                    x[i], y[i], x[(i + 1) % n], y[(i + 1) % n],
                                    x[j], y[j], x[(j + 1) % n], y[(j + 1) % n]
                            )
                    );
		/*Point2D center = SharedGeom.getPolygonCenter(x, y);
        if (center.distance(x[0], y[0]) < 1e-6)
            throw new RuntimeException("Center is too close to the first nail");*/
        int m = inf.nextInt(1, maxM);
        inf.eoln();
        for (int i = 0; i < m; i++) {
            int px = inf.nextInt(-maxC, maxC);
            int py = inf.nextInt(-maxC, maxC);
            inf.eoln();
            if (SharedGeom.checkInside(x, y, px, py))
                throw new RuntimeException(String.format("Point (%d, %d) is in polygon", px, py));

            for (int j = 0; j < n; j++) {
            	Point start = new Point(x[j], y[j]), end = new Point(x[(j + 1) % n], y[(j + 1) % n]);
         		if (containsSegment(start, end, new Point(px, py))) {
					throw new RuntimeException(String.format("Point (%d, %d) is in polygon", px, py));
            	}
            }
        }
        inf.close();
    }

    public boolean containsSegment(Point start, Point end, Point check) {
		long vm = (end.x - start.x) * (check.y - start.y) - (end.y - start.y) * (check.x - start.x);
		if (vm != 0) {
			return false;
		}

		return atSegment(start.x, end.x, check.x) && atSegment(start.y, end.y, check.y);			
    }

    public boolean atSegment(long from, long to, long check) {
    	return Math.min(from, to) <= check && check <= Math.max(from, to);
    }

	public class Point {
    	long x, y;

    	public Point(long x, long y) {
    		this.x = x;
    		this.y = y;
       }
	}
}