/*--------------------------------------------------------------*/
/* ACM ICPC 2009-2010, NEERC                                    */
/* Northern Subregional Contest                                 */
/* St Petersburg, October 17, 2009                              */
/*--------------------------------------------------------------*/
/* Problem G. Grand Theft Auto Wheel                            */
/*                                                              */
/* Original idea         Pavel Mavrin                           */
/* Problem statement     Pavel Mavrin                           */
/* Testset               Pavel Mavrin                           */
/*--------------------------------------------------------------*/
/* Solution                                                     */
/*                                                              */
/* Author                Pavel Mavrin                           */
/*--------------------------------------------------------------*/
 
import java.util.*;
import java.io.PrintWriter;
import java.io.File;
import java.io.FileNotFoundException;

public class gtaw_pm implements Runnable {

    private static final double EPS = 1e-9;

    private static int R;

    private void solve() throws FileNotFoundException {
        Scanner in = new Scanner(new File("gtaw.in"));
        PrintWriter out = new PrintWriter("gtaw.out");
        int n = in.nextInt();
        R = in.nextInt(); // The radius is ignored actually.
        Figure bolt = Figure.readFigure(in);
        Figure[] wrenches = new Figure[n];
        for (int i = 0; i < n; i++) {
            wrenches[i] = Figure.readFigure(in);
        }
        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 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};
    }

    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;
    }

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

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

    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++) {
                int r = in.nextInt();
                int a = in.nextInt();
                if (r > R) {
                    throw new RuntimeException("!!!");
                }
                p[i] = Point.polar(
                        r,
                        a * Math.PI / 180);
            }
            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};
            }
        }
    }
}
