import java.io.*;
import java.util.ArrayDeque;
import java.util.HashSet;

import java.util.ArrayList;
import java.util.Queue;

public class Validate {
    final int MAXN = 10000;
    final int MAXM = 10000;
    final int MAXK = 10000;
    final int MAXL = 200;
    final int MAXS = 3000;

    HashSet<Long> set;



    public void run() {
        StrictScanner inf = new StrictScanner(System.in);
        int n = inf.nextInt();
        int m = inf.nextInt();
        int k = inf.nextInt();
        int tl = inf.nextInt();
        inf.nextLine();
        set = new HashSet<Long>();
        ensureLimits(m, 1, MAXM, "M is incorrect");
        ensureLimits(k, 1, MAXK, "K is incorrect");
        ensureLimits(n * tl, 1, 10000, "Rak");
        for (int i = 0; i < m; i++) {
            int u = inf.nextInt();
            int v = inf.nextInt();
            int l = inf.nextInt();
            int s = inf.nextInt();
            ensureLimits(u, 1, n,  "Incorrect u in line " + Integer.toString(i+2));
            ensureLimits(v, 1, n,  "Incorrect v in line " + Integer.toString(i+2));
            ensureLimits(l, 1, MAXL,  "Incorrect l in line " + Integer.toString(i+2));
            ensureLimits(s, 1, MAXS,  "Incorrect s in line " + Integer.toString(i+2));
            ensure(u != v, "u = v in line " + Integer.toString(i+2));
            long q = (long) u * n + v;
//            long w = (long) v * n + u;
            ensure(!set.contains(q) /*&& !set.contains(w)*/, "Repeated edge! From " + Integer.toString(u) + " to " + Integer.toString(v));
            set.add(q);
//            set.add(w);
            inf.nextLine();
        } 
        inf.close();
    }

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

    public class StrictScanner {
        private final BufferedReader in;
        private String line = "";
        private int pos;
        private int lineNo;

        public StrictScanner(InputStream source) {
            in = new BufferedReader(new InputStreamReader(source));
            nextLine();
        }

        public void close() {
            ensure(line == null, "Extra data at the end of file");
            try {
                in.close();
            } catch (IOException e) {
                throw new AssertionError("Failed to close with " + e);
            }
        }

        public void nextLine() {
            ensure(line != null, "EOF");
            ensure(pos == line.length(), "Extra characters on line " + lineNo);
            try {
                line = in.readLine();
            } catch (IOException e) {
                throw new AssertionError("Failed to read line with " + e);
            }
            pos = 0;
            lineNo++;
        }

        public String next() {
            ensure(line != null, "EOF");
            ensure(line.length() > 0, "Empty line " + lineNo);
            if (pos == 0)
                ensure(line.charAt(0) > ' ', "Line " + lineNo
                        + " starts with whitespace");
            else {
                ensure(pos < line.length(), "Line " + lineNo + " is over");
                ensure(line.charAt(pos) == ' ', "Wrong whitespace on line "
                        + lineNo);
                pos++;
                ensure(pos < line.length(), "Line " + lineNo + " is over");
                ensure(line.charAt(0) > ' ', "Line " + lineNo
                        + " has double whitespace");
            }
            StringBuilder sb = new StringBuilder();
            while (pos < line.length() && line.charAt(pos) > ' ')
                sb.append(line.charAt(pos++));
            return sb.toString();
        }

        public int nextInt() {
            String s = next();
            ensure(s.length() == 1 || s.charAt(0) != '0',
                    "Extra leading zero in number " + s + " on line " + lineNo);
            ensure(s.charAt(0) != '+', "Extra leading '+' in number " + s
                    + " on line " + lineNo);
            try {
                return Integer.parseInt(s);
            } catch (NumberFormatException e) {
                throw new AssertionError("Malformed number " + s + " on line "
                        + lineNo);
            }
        }

        public long nextLong() {
            String s = next();
            ensure(s.length() == 1 || s.charAt(0) != '0',
                    "Extra leading zero in number " + s + " on line " + lineNo);
            ensure(s.charAt(0) != '+', "Extra leading '+' in number " + s
                    + " on line " + lineNo);
            try {
                return Long.parseLong(s);
            } catch (NumberFormatException e) {
                throw new AssertionError("Malformed number " + s + " on line "
                        + lineNo);
            }
        }

        public double nextDouble() {
            String s = next();
            ensure(s.length() == 1 || s.startsWith("0.") || s.charAt(0) != '0',
                    "Extra leading zero in number " + s + " on line " + lineNo);
            ensure(s.charAt(0) != '+', "Extra leading '+' in number " + s
                    + " on line " + lineNo);
            try {
                return Double.parseDouble(s);
            } catch (NumberFormatException e) {
                throw new AssertionError("Malformed number " + s + " on line "
                        + lineNo);
            }
        }
    }

    void ensure(boolean b, String message) {
        if (!b) {
            throw new AssertionError(message);
        }
    }

    void ensureLimits(long n, long from, long to, String name) {
        ensure(from <= n && n <= to, name + " must be from " + from + " to "
                + to);
    }

    void ensureLimits(int n, int from, int to, String name) {
        ensure(from <= n && n <= to, name + " must be from " + from + " to "
                + to);
    }

}