// This program prints the solution for the hard version of Assignment 1
// in YUFAFF.
// To number the states, we let
// state number 10*s_odd + s_even represent (even, s_odd, s_even)
// and state 100 + 10*s_odd + s_even represent (odd, s_odd, s_even)

import java.io.PrintStream;
    
public class A1Gen {
    static final PrintStream out = System.out;

    public static void printTransition(int oldq, int a, int newq) {
	out.print(oldq);
	out.print(" ");
	out.print(a);
	out.print(" ");
	out.println(newq);
    }

    public static int f(int x) {
	return (2*x >= 10 ? 2*x-9 : 2*x);
    }

    public static int odd = 100;
    public static int even = 0;
    
    public static int state(int parity, int sodd, int seven) {
	// compute state number of given state triple
	return parity + 10*sodd + seven;
    }
	
    public static void main(String[] args) {
	out.println("200 10 20 2000");
	out.println("0 1 2 3 4 5 6 7 8 9");
	out.println("0 10 20 30 40 50 60 70 80 90 100 101 102 103 104 105 106 107 108 109");
	for (int sodd = 0; sodd < 10; sodd++)
	    for (int seven = 0; seven < 10; seven++)
		for (int d = 0; d < 10; d++) {
		    // delta((even, sodd, seven), d)
		    // = (odd, (sodd+d) mod 10, (seven + f(d)) mod 10)
		    printTransition(state(even, sodd, seven), d, state(odd, (sodd+d)%10, (seven + f(d))%10));
		    // delta((odd, sodd, seven), d)
		    // = (even, (sodd+f(d)) mod 10, (seven+d) mod 10)
		    printTransition(state(odd, sodd, seven), d, state(even, (sodd+f(d))%10, (seven+d)%10));
		}
    }
}
