import javax.swing.*;
import java.util.*;
import java.util.List;
import java.io.PrintWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;

public class gtaw_pm_vis implements Runnable {

    private static final double EPS = 1e-9;
    private static final int SIZE = 1000;

    BufferedImage image;

    Figure bolt;
    Figure[] wrenches;
    int wn;

    private void solve() throws FileNotFoundException {
        Scanner in = new Scanner(new File("gtaw.in"));
        PrintWriter out = new PrintWriter("gtaw.out");
        int n = in.nextInt();
        int r = in.nextInt();
        bolt = Figure.readFigure(in);
        wrenches = new Figure[n];
        wn = 0;
        for (int i = 0; i < n; i++) {
            wrenches[i] = Figure.readFigure(in);
        }

        image = drawCase(bolt, wrenches[wn]);
        final JPanel panel = new JPanel() {
            @Override
            public void paint(Graphics g) {
                g.drawImage(image, 0, 0, null);
            }
        };

        JFrame mainFrame = new JFrame("GTAW Visualizer");
        mainFrame.setLayout(new BorderLayout());
        mainFrame.getContentPane().add(panel);
        mainFrame.setSize(SIZE + 10, SIZE + 25);
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        mainFrame.addKeyListener(
                new KeyAdapter() {
                    @Override
                    public void keyTyped(KeyEvent e) {
                        wn++;
                        if (wn == wrenches.length) wn = 0;
                        image = drawCase(bolt, wrenches[wn]);
                        panel.repaint();
                    }
                }
        );
        mainFrame.setVisible(true);

        List<Integer> res = new ArrayList<Integer>();
        for (int i = 0; i < n; i++) {
            if (canOpen(bolt, wrenches[i])) {
                res.add(i + 1);
            }
        }
        out.println(res.size());
        for (int i = 0; i < res.size(); i++) {
            if (i > 0) out.print(" ");
            out.print(res.get(i));
        }
        out.println();

        in.close();
        out.close();
    }

    private BufferedImage drawCase(Figure bolt, Figure wrench) {
        double r = 0;
        for (Point p : bolt.p) {
            r = Math.max(r, p.r);
        }
        for (Point p : wrench.p) {
            r = Math.max(r, p.r);
        }
        r = r * 1.1;
        BufferedImage bi = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_RGB);
        Graphics2D g = (Graphics2D) bi.getGraphics();

        g.fill(new Rectangle(0, 0, SIZE, SIZE));
        g.setColor(Color.black);
        g.drawString("Wrench " + wn, 0, 50);
        g.drawOval(SIZE / 2 - 1, SIZE / 2 - 1, 3, 3);

        grawFigure(g, r, bolt, Color.black);

        double an = getAngle(bolt, wrench);
        System.out.println(an);
        if (an == -1) {
            grawFigure(g, r, wrench, Color.red);
        } else {
            grawFigure(g, r, wrench.rotated(an), Color.green);
        }

        return bi;
    }

    private double getAngle(Figure bolt, Figure wrench) {
        List<Segment> forbiddenSegments = new ArrayList<Segment>();
        for (int i = 0; i < bolt.n; i++) {
            for (int j = 0; j < wrench.n; j++) {
                for (int ii = i; ii <= i + 1; ii++) {
                    double[] a = calcAnglesForPointAndLine(bolt.p[ii], wrench.p[j], wrench.p[j + 1]);
                    if (a != null) {
                        Segment[] s = new Segment(-a[0] + EPS, -a[1] - EPS).intersectWith(
                                new Segment(wrench.p[j + 1].angleTo(bolt.p[ii]) - EPS,
                                        wrench.p[j].angleTo(bolt.p[ii]) + EPS));
                        forbiddenSegments.addAll(Arrays.asList(s));
                    } else {
                        forbiddenSegments.add(new Segment(wrench.p[j + 1].angleTo(bolt.p[ii]) - EPS,
                                wrench.p[j].angleTo(bolt.p[ii]) + EPS));
                    }
                }
                for (int jj = j; jj <= j + 1; jj++) {
                    double[] a = calcAnglesForPointAndLine(wrench.p[jj], bolt.p[i], bolt.p[i + 1]);
                    if (a != null) {
                        Segment[] s = new Segment(a[0] + EPS, a[1] - EPS).intersectWith(
                                new Segment(wrench.p[jj].angleTo(bolt.p[i]) - EPS,
                                        wrench.p[jj].angleTo(bolt.p[i + 1]) + EPS));
                        forbiddenSegments.addAll(Arrays.asList(s));
                    }
                }
            }
        }
        if (forbiddenSegments.size() == 0) return -1;
        Collections.sort(forbiddenSegments, new Comparator<Segment>() {
            public int compare(Segment a, Segment b) {
                return Double.compare(a.begin, b.begin);
            }
        });
        double r = -Math.PI * 2;
        for (Segment segment : forbiddenSegments) {
            r = Math.max(r, segment.end - Math.PI * 2);
        }
        if (r <= 0) return r;
        for (Segment segment : forbiddenSegments) {
            if (segment.begin > r) return r;
            r = Math.max(r, segment.end);
        }
        return -1;
    }

    private void grawFigure(Graphics2D g, double r, Figure figure, Color color) {
        for (int i = 0; i < figure.n; i++) {
            g.setColor(color);
            g.drawLine(
                    getX(figure.p[i].x, r),
                    getY(figure.p[i].y, r),
                    getX(figure.p[i + 1].x, r),
                    getY(figure.p[i + 1].y, r)
            );
            Point p = Point.polar(figure.p[i].r + r * 0.02, figure.p[i].a);
            g.drawString("" + i, getX(p.x, r) - 5, getY(p.y, r) + 5);
        }
    }

    private int getX(double x, double r) {
        return (int) (SIZE / 2 + (x / r * SIZE / 2));
    }

    private int getY(double y, double r) {
        return (int) (SIZE / 2 - (y / r * SIZE / 2));
    }

    private boolean canOpen(Figure bolt, Figure wrench) {
        List<Segment> forbiddenSegments = new ArrayList<Segment>();
        for (int i = 0; i < bolt.n; i++) {
            for (int j = 0; j < wrench.n; j++) {
                for (int ii = i; ii <= i + 1; ii++) {
                    double[] a = calcAnglesForPointAndLine(bolt.p[ii], wrench.p[j], wrench.p[j + 1]);
                    if (a != null) {
                        Segment[] s = new Segment(-a[0] + EPS, -a[1] - EPS).intersectWith(
                                new Segment(wrench.p[j + 1].angleTo(bolt.p[ii]) - EPS,
                                        wrench.p[j].angleTo(bolt.p[ii]) + EPS));
                        forbiddenSegments.addAll(Arrays.asList(s));
                    } else {
                        forbiddenSegments.add(new Segment(wrench.p[j + 1].angleTo(bolt.p[ii]) - EPS,
                                wrench.p[j].angleTo(bolt.p[ii]) + EPS));
                    }
                }
                for (int jj = j; jj <= j + 1; jj++) {
                    double[] a = calcAnglesForPointAndLine(wrench.p[jj], bolt.p[i], bolt.p[i + 1]);
                    if (a != null) {
                        Segment[] s = new Segment(a[0] + EPS, a[1] - EPS).intersectWith(
                                new Segment(wrench.p[jj].angleTo(bolt.p[i]) - EPS,
                                        wrench.p[jj].angleTo(bolt.p[i + 1]) + EPS));
                        forbiddenSegments.addAll(Arrays.asList(s));
                    }
                }
            }
        }
        if (forbiddenSegments.size() == 0) return false;
        Collections.sort(forbiddenSegments, new Comparator<Segment>() {
            public int compare(Segment a, Segment b) {
                return Double.compare(a.begin, b.begin);
            }
        });
        double r = 0;
        for (Segment segment : forbiddenSegments) {
            r = Math.max(r, segment.end - Math.PI * 2);
        }
        if (r == 0) return true;
        for (Segment segment : forbiddenSegments) {
            if (segment.begin > r) return true;
            r = Math.max(r, segment.end);
        }
        return false;
    }

    private double[] calcAnglesForPointAndLine(Point p, Point a, Point b) {
        double A = a.y - b.y;
        double B = b.x - a.x;
        double d = Math.hypot(A, B);
        A /= d;
        B /= d;
        double C = -A * a.x - B * a.y;
        Point o = Point.cartesian(-C * A, -C * B);
        double cos = o.r / p.r;
        if (cos > 1 + EPS) return null;
        if (cos > 1) cos = 1;
        double da = Math.acos(cos);
        double an = p.angleTo(o);
        double a1 = normalizeAngle(an - da);
        double a2 = normalizeAngle(an + da);
        return new double[]{a1, a2};
    }

    public static void main(String[] args) {
        new gtaw_pm_vis().run();
    }

    public void run() {
        try {
            solve();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    private static double normalizeAngle(double a) {
        while (a < 0) a += Math.PI * 2;
        while (a > Math.PI * 2 - EPS) a -= Math.PI * 2;
        return a;
    }

    private static class Figure {
        int n;
        Point[] p;

        private Figure(int n, Point[] p) {
            this.n = n;
            this.p = p;
        }

        public static Figure readFigure(Scanner in) {
            int n = in.nextInt();
            Point[] p = new Point[n + 1];
            for (int i = 0; i < n; i++) {
                p[i] = Point.polar(
                        in.nextInt(),
                        in.nextInt() * Math.PI / 180);
            }
            p[n] = p[0];
            return new Figure(n, p);
        }

        public Figure rotated(double a) {
            Point[] p = new Point[n + 1];
            for (int i = 0; i < n; i++) {
                p[i] = Point.polar(this.p[i].r, this.p[i].a + a);
            }
            Arrays.sort(p, 0, n, new Comparator<Point>() {
                public int compare(Point a, Point b) {
                    return Double.compare(a.a, b.a);
                }
            });
            p[n] = p[0];
            return new Figure(n, p);
        }
    }

    private static class Point {
        double r;
        double a;
        double x;
        double y;
        private static final double EPS = 1e-9;

        private Point(double r, double a, double x, double y) {
            this.r = r;
            this.a = a;
            this.x = x;
            this.y = y;
        }

        public static Point cartesian(double x, double y) {
            return new Point(
                    Math.hypot(x, y),
                    Math.atan2(y, x),
                    x,
                    y
            );
        }

        public static Point polar(double r, double a) {
            return new Point(
                    r,
                    a,
                    r * Math.cos(a),
                    r * Math.sin(a)
            );
        }

        public double angleTo(Point point) {
            return normalizeAngle(point.a - a);
        }
    }

    private static class Segment {
        double begin;
        double end;

        private Segment(double begin, double end) {
            begin = normalizeAngle(begin);
            end = normalizeAngle(end);
            if (end < begin) end += Math.PI * 2;
            this.begin = begin;
            this.end = end;
        }

        public Segment[] intersectWith(Segment segment) {
            double b1 = begin;
            double e1 = end;
            double b2 = segment.begin;
            double e2 = segment.end;
            if (b2 > b1) {
                b2 -= Math.PI * 2;
                e2 -= Math.PI * 2;
            }
            double b = Math.max(b1, b2);
            double e = Math.min(e1, e2);
            Segment s1 = null;
            if (e > b + EPS) {
                s1 = new Segment(b, e);
            }
            b2 += Math.PI * 2;
            e2 += Math.PI * 2;
            b = Math.max(b1, b2);
            e = Math.min(e1, e2);
            if (e > b + EPS) {
                Segment s2 = new Segment(b, e);
                if (s1 == null) return new Segment[]{s2}; else return new Segment[]{s1, s2};
            } else {
                if (s1 == null) return new Segment[]{}; else return new Segment[]{s1};
            }
        }
    }
}
