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

public class TestsGen {
    static class Test {
        int[][] a;
        int k;

        Test(int[][] a, int k) {
            this.a = a;
            this.k = k;
        }
    }

    static int testsCount;

    static void printTest(Test test) {
        try {
            System.err.println("[" + ++testsCount + "]");
            PrintWriter out = new PrintWriter("../tests/" + testsCount / 10 + "" + testsCount % 10);
            out.println(test.a.length + " " + test.k);
            for (int[] e : test.a) {
                out.println(e[0] + " " + e[1] + " " + e[2]);
            }
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    static final int N = 100000;

    static final Random rand = new Random(1029384756);

    static Test getMaxTest() {
        int n = N;
        int k = rand.nextInt(n) + 1;
        int[][] a = new int[n][3];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 3; j++) {
                a[i][j] = rand.nextInt(256);
            }
        }
        return new Test(a, k);
    }

    static Test getTest(int n, int maxColor) {
        int k = rand.nextInt(n - 2) + 2;
        int[][] a = new int[n][3];
        int[] d = new int[3];
        for (int i = 0; i < 3; i++) {
            d[i] = rand.nextInt(256 - maxColor);
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 3; j++) {
                a[i][j] = rand.nextInt(maxColor) + d[j];
            }
        }
        return new Test(a, k);
    }

    static Test getTestLargeK(int n, int maxColor) {
        int k = rand.nextInt(11) + n - 10;
        int[][] a = new int[n][3];
        int[] d = new int[3];
        for (int i = 0; i < 3; i++) {
            d[i] = rand.nextInt(256 - maxColor);
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 3; j++) {
                a[i][j] = rand.nextInt(maxColor) + d[j];
            }
        }
        return new Test(a, k);
    }

    public static void main(String[] args) {
        testsCount = 0;
        printTest(new Test(new int[][]{{255, 255, 255}, {0, 0, 0}}, 2));
        printTest(new Test(new int[][]{{255, 255, 0}, {255, 0, 255}, {0, 255, 255},
                {255, 255, 255}}, 2));
        printTest(new Test(new int[][]{{13, 14, 15}, {15, 14, 13}}, 1));
        for (int i = 11; i <= 20; i++) {
            printTest(getTest(i, rand.nextInt(10) + 10));
        }
        printTest(getMaxTest());
        printTest(getMaxTest());
        printTest(getMaxTest());
        for (int i = 0; i < 5; i++) {
            printTest(getTest(1234 + i, rand.nextInt(20) + 10));
        }
        for (int i = 0; i < 5; i++) {
            printTest(getTest(N - i, rand.nextInt(20) + 10));
        }
        for (int i = 0; i < 5; i++) {
            printTest(getTest(N - i, rand.nextInt(100) + 150));
        }
        for (int i = 0; i < 5; i++) {
            printTest(getTestLargeK(N - i, rand.nextInt(30) + 200));
        }
    }
}
