import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;

public class TestGen {
    public static void main(String[] args) {
        for (int i : new int[] { 10, 12, 15, 20, 25, 30, 40, 50, 100, 150, 200 }) {
            printTest(getRandom(i, 500 / i / 2));
        }
        for (int i : new int[] { 10, 12, 15, 20, 25, 30, 40, 50, 100, 150, 200,
                300, 350, 500, 600, 1000, 2000 }) {
            printTest(getRandom(i, 10000 * 4 / i));
        }
    }

    static final Random RNG = new Random(58L);

    static Test getRandom(int v, int limit) {
        int m = 2 * v;
        Set<Edge> z = new HashSet<>();
        Edge[] edges = new Edge[m];
        for (int i = 0; i < m; i++) {
            int x, y;
            do {
                x = RNG.nextInt(v);
                y = RNG.nextInt(v);
            } while (x == y || !z.add(new Edge(x, y, 0, 0)));
            edges[i] = new Edge(x, y, RNG.nextInt(1000000) + 1,
                    RNG.nextInt(limit / 2 + 2) + 1);
        }
        return new Test(v, RNG.nextInt(1000000), limit, edges);
    }

    static int testNum;

    static void printTest(Test test) {
        System.err.println("[" + ++testNum + "]");
        try {
            PrintWriter out = new PrintWriter("../tests/" + testNum / 10 + ""
                    + testNum % 10);
            out.println(test.n + " " + test.edges.length + " " + test.k + " "
                    + test.tl);
            for (Edge e : test.edges) {
                out.println(e.from + 1 + " " + (e.to + 1) + " " + e.length
                        + " " + e.cap);
            }
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    static class Edge {
        int from;
        int to;
        int cap;
        int length;

        @Override
        public int hashCode() {
            final int prime = 31;
            int result = 1;
            result = prime * result + from;
            result = prime * result + to;
            return result;
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            Edge other = (Edge) obj;
            if (from != other.from)
                return false;
            if (to != other.to)
                return false;
            return true;
        }

        public Edge(int from, int to, int cap, int length) {
            this.from = from;
            this.to = to;
            this.cap = cap;
            this.length = length;
        }

    }

    static class Test {
        int n;
        int k;
        int tl;
        Edge[] edges;

        public Test(int n, int k, int tl, Edge[] edges) {
            this.n = n;
            this.k = k;
            this.tl = tl;
            this.edges = edges;
        }

    }
}
