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

public class doall {

    static Random random = new Random(436567454);

    static int testNumber;

    static void printTest(int n, int[] l, int[][] a, int p, int[] s, int[] d, int[] t) throws FileNotFoundException {
        testNumber++;
        PrintWriter out = new PrintWriter("" + (testNumber / 10) + (testNumber % 10));
        out.println(n);
        for (int i = 0; i < n; i++) {
            out.print(l[i]);
            for (int j = 0; j < l[i]; j++) {
                out.print(" " + (a[i][j] + 1));
            }
            out.println();
        }
        out.println(p);
        for (int i = 0; i < p; i++) {
            out.println("" + (s[i] + 1) + " " + (d[i] + 1) + " " + t[i]);
        }
        out.close();
    }

    public static void main(String[] args) throws FileNotFoundException {
        printTest(4,
                new int[]{2, 3, 3, 1},
                new int[][]{{1, 2}, {0, 0, 2}, {3, 3, 1}, {2}},
                3,
                new int[]{0, 2, 3},
                new int[]{2, 0, 1},
                new int[]{0, 2, 3});

        for (int i = 0; i < 5; i++) {
            printRandomTest(10, 20, 20);
        }

        for (int i = 0; i < 10; i++) {
            printRingTest(100, 100, (i + 1) * 100);
        }
        for (int i = 0; i < 10; i++) {
            printPermTest(100, 100, (i + 1) * 100);
        }

        for (int i = 0; i < 10; i++) {
            printLineTest(100, 100, (i + 1) * 100);
        }

        for (int i = 0; i < 10; i++) {
            printLineTest2(100, 100, (i + 1) * 100);
        }
        for (int i = 0; i < 10; i++) {
            printLongPathTest(89, 100, (i + 1) * 100);
        }

        for (int i = 0; i < 10; i++) {
            printRandomTest(100, 100, (i + 1) * 100);
        }
        for (int i = 0; i < 20; i++) {
            printMaxTest(100, 100, (i + 1) * 50);
        }
    }

    private static void printLongPathTest(int n, int p, int tt) throws FileNotFoundException {
        n += 4;
        int[] l = new int[n];
        int[][] a = new int[n][];
        int[] perm = new int[n];
        for (int i = 0; i < n; i++) perm[i] = i;
        for (int i = 0; i < n; i++) {
            int j = random.nextInt(i + 1);
            int t = perm[j];
            perm[j] = perm[i];
            perm[i] = t;
        }
        l[perm[0]] = 1;
        a[perm[0]] = new int[]{perm[9]};
        l[perm[1]] = 8;
        a[perm[1]] = new int[]{perm[0], perm[8], perm[8], perm[8], perm[8], perm[8], perm[8], perm[8]};
        l[perm[2]] = 3;
        a[perm[2]] = new int[]{perm[1], perm[7], perm[7], perm[7], perm[7], perm[7], perm[7], perm[7], perm[7]};
        l[perm[3]] = 5;
        a[perm[3]] = new int[]{perm[2], perm[6], perm[6], perm[6], perm[6]};
        l[perm[4]] = 7;
        a[perm[4]] = new int[]{perm[3], perm[5], perm[5], perm[5], perm[5], perm[5], perm[5]};

        for (int i = 5; i < n - 1; i++) {
            l[perm[i]] = 1;
            a[perm[i]] = new int[]{perm[i + 1]};
        }
        l[perm[n - 1]] = 1;
        a[perm[n - 1]] = new int[]{perm[4]};

        int[] s = new int[p];
        int[] d = new int[p];
        int[] t = new int[p];
        for (int i = 0; i < p; i++) {
            do {
                s[i] = random.nextInt(n);
                d[i] = perm[0];
            } while (s[i] == d[i]);
            t[i] = random.nextInt(tt);
        }
        printTest(n, l, a, p, s, d, t);
    }

    private static void printLineTest(int n, int p, int tt) throws FileNotFoundException {
        int[] l = new int[n];
        int[][] a = new int[n][];
        int[] perm = new int[n];
        for (int i = 0; i < n; i++) perm[i] = i;
        for (int i = 0; i < n; i++) {
            int j = random.nextInt(i + 1);
            int t = perm[j];
            perm[j] = perm[i];
            perm[i] = t;
        }
        l[perm[0]] = 1;
        a[perm[0]] = new int[]{perm[1]};
        l[perm[n - 1]] = 1;
        a[perm[n - 1]] = new int[]{perm[n - 2]};

        for (int i = 1; i < n - 1; i++) {
            l[perm[i]] = random.nextInt(7) + 2;
            a[perm[i]] = new int[l[perm[i]]];
            boolean c1, c2;
            do {
                c1 = c2 = false;
                for (int j = 0; j < l[perm[i]]; j++) {
                    if (random.nextBoolean()) {
                        if (i < n - 2 && random.nextBoolean()) {
                            a[perm[i]][j] = perm[i + 2];
                        } else {
                            a[perm[i]][j] = perm[i + 1];
                        }
                        c1 = true;
                    } else {
                        if (i > 1 && random.nextBoolean()) {
                            a[perm[i]][j] = perm[i - 2];
                        } else {
                            a[perm[i]][j] = perm[i - 1];
                        }
                        c2 = true;
                    }
                }
            } while (!(c1 && c2));
        }

        int[] s = new int[p];
        int[] d = new int[p];
        int[] t = new int[p];
        for (int i = 0; i < p; i++) {
            do {
                s[i] = random.nextInt(n);
                d[i] = random.nextInt(n);
            } while (s[i] == d[i]);
            t[i] = random.nextInt(tt);
        }
        printTest(n, l, a, p, s, d, t);
    }

    private static void printLineTest2(int n, int p, int tt) throws FileNotFoundException {
        int[] l = new int[n];
        int[][] a = new int[n][];
        int[] perm = new int[n];
        for (int i = 0; i < n; i++) perm[i] = i;
        for (int i = 0; i < n; i++) {
            int j = random.nextInt(i + 1);
            int t = perm[j];
            perm[j] = perm[i];
            perm[i] = t;
        }
        l[perm[0]] = 1;
        a[perm[0]] = new int[]{perm[2]};
        l[perm[n - 1]] = 1;
        a[perm[n - 1]] = new int[]{perm[n - 3]};

        for (int i = 1; i < n - 1; i++) {
            l[perm[i]] = 2;
            a[perm[i]] = new int[l[perm[i]]];
            if (i % 2 == 0) {
                a[perm[i]][0] = perm[i + 1];
                a[perm[i]][1] = perm[i - 1];
            } else {
                a[perm[i]][0] = perm[i - 1];
                a[perm[i]][1] = perm[i + 1];
            }
        }

        int[] s = new int[p];
        int[] d = new int[p];
        int[] t = new int[p];
        for (int i = 0; i < p; i++) {
            do {
                s[i] = random.nextInt(n);
                d[i] = random.nextInt(n);
            } while (s[i] == d[i]);
            t[i] = random.nextInt(tt);
        }
        printTest(n, l, a, p, s, d, t);
    }

    private static void printPermTest(int n, int p, int tt) throws FileNotFoundException {
        int[] l = new int[n];
        int[][] a = new int[n][1];
        int[] perm = new int[n];
        for (int i = 0; i < n; i++) perm[i] = i;
        for (int i = 0; i < n; i++) {
            int j = random.nextInt(i + 1);
            int t = perm[j];
            perm[j] = perm[i];
            perm[i] = t;
        }
        for (int i = 0; i < n; i++) {
            l[i] = 1;
            a[i][0] = perm[i % n];
        }

        int[] s = new int[p];
        int[] d = new int[p];
        int[] t = new int[p];
        for (int i = 0; i < p; i++) {
            do {
                s[i] = random.nextInt(n);
                d[i] = random.nextInt(n);
            } while (s[i] == d[i]);
            t[i] = random.nextInt(tt);
        }
        printTest(n, l, a, p, s, d, t);
    }

    private static void printRingTest(int n, int p, int tt) throws FileNotFoundException {
        int[] l = new int[n];
        int[][] a = new int[n][1];
        int[] perm = new int[n];
        for (int i = 0; i < n; i++) perm[i] = i;
        for (int i = 0; i < n; i++) {
            int j = random.nextInt(i + 1);
            int t = perm[j];
            perm[j] = perm[i];
            perm[i] = t;
        }
        for (int i = 0; i < n; i++) {
            l[perm[i]] = 1;
            a[perm[i]][0] = perm[(i + 1) % n];
        }

        int[] s = new int[p];
        int[] d = new int[p];
        int[] t = new int[p];
        for (int i = 0; i < p; i++) {
            do {
                s[i] = random.nextInt(n);
                d[i] = random.nextInt(n);
            } while (s[i] == d[i]);
            t[i] = random.nextInt(tt);
        }
        printTest(n, l, a, p, s, d, t);
    }

    private static void printMaxTest(int n, int p, int tt) throws FileNotFoundException {
        int[] l = new int[n];
        int[][] a = new int[n][];
        for (int i = 0; i < n; i++) {
            l[i] = random.nextInt(8) + 1;
            a[i] = new int[l[i]];
            for (int j = 0; j < l[i]; j++) {
                a[i][j] = random.nextInt(n);
            }
        }

        int[] s = new int[p];
        int[] d = new int[p];
        int[] t = new int[p];
        for (int i = 0; i < p; i++) {
            do {
                s[i] = random.nextInt(n);
                d[i] = random.nextInt(n);
            } while (s[i] == d[i]);
            t[i] = random.nextInt(tt);
        }
        printTest(n, l, a, p, s, d, t);
    }

    private static void printRandomTest(int nn, int pp, int tt) throws FileNotFoundException {
        printMaxTest(nn - random.nextInt(nn / 2), pp - random.nextInt(pp / 2), tt);
    }
}
