import javax.swing.*;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.Path2D;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import java.io.*;
import java.lang.*;
import java.util.*;


/**
 * Created with IntelliJ IDEA.
 * User: Pavel Kunyavskiy
 * Date: 18/10/13
 * Time: 21:01
 */


public class Visualizer extends JPanel {
    public static void main(String[] args) throws Exception {
        Locale.setDefault(Locale.US);
        JFrame fr = new JFrame("Visualizer");
        Visualizer me;
        if (args.length == 1)
           me = new Visualizer(new FileInputStream(args[0]));
        else
           me = new Visualizer(System.in);
        fr.add(me);
        fr.pack();
        fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        fr.setVisible(true);
    }

    public Visualizer(InputStream stream) {
        try {
            load(stream);
        } catch (Exception e) {
            System.err.println("Cannot load file");
            e.printStackTrace();
            System.exit(239);
        }
        setPreferredSize(new Dimension(640, 480));
    }

    public void load(InputStream inputStream) throws Exception {
        Scanner in = new Scanner(inputStream);
        p = new ArrayList<Pt>();
        s = new ArrayList<Segment>();
        s2 = new ArrayList<Segment>();
        int n = in.nextInt();
        int[] x = new int[n];
        int[] y = new int[n];
        for (int i = 0; i < n; i++){
            x[i] = in.nextInt();
            y[i] = in.nextInt();
        }
//        for (int i = 0; i < n; i++)
//            addSegment(s, new Pt(x[i], y[i]), new Pt(x[(i+1)%n], y[(i+1)%n]));
        Path2D polygon = new Path2D.Double();
        polygon.moveTo(x[0],y[0]);
        for (int i = 1; i < x.length; i++)
            polygon.lineTo(x[i], y[i]);
        polygon.lineTo(x[0],y[0]);

        PathIterator iter = polygon.getPathIterator(new AffineTransform());
        //Point2D center = SharedGeom.getPolygonCenter(x, y);
        //addPoint(new Pt(center.getX(), center.getY(), Color.BLUE));
        //center = SharedGeom.getRotatedPolygonCenter(x, y);
        //addPoint(new Pt(center.getX(), center.getY(), Color.BLUE));
        double[] xr = new double[n];
        double[] yr = new double[n];
        int ptr = 0;
        while (!iter.isDone()){
            double[] coords = new double[6];
            if (iter.currentSegment(coords) == PathIterator.SEG_LINETO){
                xr[ptr] = coords[0];
                yr[ptr] = coords[1];
                ptr++;
            }
            iter.next();
        }
        assert ptr == n;
        for (int i = 0; i < n; i++)
            addSegment(s2, new Pt(xr[i], yr[i]), new Pt(xr[(i+1)%n], yr[(i+1)%n]));

        addPoint(new Pt(x[0], y[0], Color.BLACK));
        int m = in.nextInt();
        for (int i = 0; i < m; i++)
            addPoint(new Pt(in.nextInt(), in.nextInt(), Color.RED));
    }

    class Pt {
        public double x, y;
        Color color;
        public Pt(double x, double y) { this.x = x; this.y = y; this.color = Color.BLACK;}
        public Pt(double x, double y, Color color) { this.x = x; this.y = y; this.color = color;}
    }
    class Segment {
        public Pt a,b;
        public Segment(Pt a,Pt b) { this.a = a; this.b = b;}
    }


    double scale;
    double centx, centy;
    ArrayList<Pt> p;
    ArrayList<Segment> s;
    ArrayList<Segment> s2;

    double minx, miny, maxx, maxy;
    void _addPoint(Pt p) {
        minx = Math.min(minx, p.x);
        maxx = Math.max(maxx, p.x);
        miny = Math.min(miny, p.y);
        maxy = Math.max(maxy, p.y);
    }
    void addPoint(Pt pts){
        _addPoint(pts);
        p.add(pts);
    }
    void addSegment(ArrayList<Segment> s, Pt pt1,Pt pt2){
        _addPoint(pt1);
        _addPoint(pt2);
        s.add(new Segment(pt1,pt2));
    }
    void recalcScale() {
        centx = (minx + maxx) / 2;
        centy = (miny + maxy) / 2;
        scale = Math.min(
                getWidth() / ((maxx - minx) * 1.1),
                getHeight() / ((maxy - miny) * 1.1)
        );
    }

    int x(double x) { return (int)((x - centx) * scale + getWidth() / 2); }
    int y(double y) { return (int)(-(y - centy) * scale + getHeight() / 2); }

    public void paint(Graphics _g) {
        super.paint(_g);
        recalcScale();
        Graphics2D g = (Graphics2D)_g;
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, getWidth(), getHeight());

        for (Segment i : s2){
            g.setColor(Color.BLACK);
            g.drawLine(x(i.a.x),y(i.a.y),x(i.b.x),y(i.b.y));
        }

        for (Pt i : p){
            g.setColor(i.color);
            g.fillOval(x(i.x)-3,y(i.y)-3,6,6);
        }

        for (Segment i : s){
            final float dash1[] = {10.0f};
            g.setStroke(new BasicStroke(1.0f,BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f));
            g.setColor(Color.GRAY);
            g.drawLine(x(i.a.x),y(i.a.y),x(i.b.x),y(i.b.y));
        }
    }
}
