import java.util.*;

// abstract checker

public class JohnChecker
{
	public static final int MINND = 2;
	public static final int MAXN = 1000;
	public static final int MINANG = 1;
	public static final int MAXANG = 180;
	public static final int MINM = 1;
	public static final int MAXM = 5;
	public static final int MINLEN = 1;
	public static final int MAXLEN = 20;
	public static final int MINA = 0;
	public static final int MAXA = 359;

    public static void printError(int line, String msg)
	{
		System.out.println("ERROR Line " + line + ": " + msg);
		System.exit(-1);
	}

    public static void checkIntBounds(int x, int min, int max, String name, int nLines)
    {
        if (x < min || x > max)
            printError(nLines, "invalid " + name + " value: " + x);
    }

    public static void main(String [] args)
	{
		Scanner in = new Scanner(System.in);
		int n, d, a1, a2;
		String line;
		int nLines=0;

        line = in.nextLine();
        nLines++;
        StringTokenizer st = new StringTokenizer(line);
        if (st.countTokens() != 4)
            printError(nLines, "number of values on line incorrect");
        n = Integer.parseInt(st.nextToken());
        d = Integer.parseInt(st.nextToken());
        a1 = Integer.parseInt(st.nextToken());
        a2 = Integer.parseInt(st.nextToken());
        checkIntBounds(n, MINND, MAXN, "n", nLines);
        checkIntBounds(d, MINND, n, "d", nLines);
        checkIntBounds(a1, MINANG, MAXANG, "a1", nLines);
        checkIntBounds(a2, MINANG, MAXANG, "a2", nLines);

        boolean [][] check = new boolean[n+1][n+1];
        for(int i=0; i<=n; i++)
            for(int j=0; j<=n; j++)
                check[i][j] = false;
        for(int i=1; i<=n; i++) {
            line = in.nextLine();
            nLines++;
            st = new StringTokenizer(line);
            if (st.countTokens() == 0)
                printError(nLines, "number of values on line incorrect");
            int m = Integer.parseInt(st.nextToken());
            checkIntBounds(m, MINM, MAXM, "m", nLines);
            if (st.countTokens() != 3*m)
                printError(nLines, "number of values on line incorrect");
            for(int j=1; j<=m; j++) {
                int junc = Integer.parseInt(st.nextToken());
                checkIntBounds(junc, 1, n, "d_"+j, nLines);
                if (junc == i)
                    printError(nLines, "self loop at junction " + i);
                if (check[i][junc]) {
                    printError(nLines, "multiple path between " + i + " and " + junc);
                }
                check[i][junc] = true;
                int len = Integer.parseInt(st.nextToken());
                checkIntBounds(len, MINLEN, MAXLEN, "l_"+j, nLines);
                int ang = Integer.parseInt(st.nextToken());
                checkIntBounds(ang, MINA, MAXA, "alpha_"+j, nLines);
            }
        }
		if (in.hasNextLine())
			printError(nLines, "incorrect number of lines");
        System.exit(42);
	}
}
