import java.io.*;
import java.util.*;

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

    class Query {
        int type;

        public Query(int type) {
            this.type = type;
        }

    }

    class QueryType1 extends Query {
        int x1, y1, x2, y2, x, y;

        public QueryType1(int x1, int y1, int x2, int y2, int x, int y) {
            super(1);
            this.x1 = x1;
            this.y1 = y1;
            this.x2 = x2;
            this.y2 = y2;
            this.x = x;
            this.y = y;
        }

        @Override
        public String toString() {
            return "1 " + x1 + " " + y1 + " " + x2 + " " + y2 + " " + x + " "
                    + y;
        }
    }

    class QueryType2 extends Query {
        int k;

        public QueryType2(int k) {
            super(2);
            this.k = k;
        }

        @Override
        public String toString() {
            return "2 " + k;
        }
    }

    class QueryType3 extends Query {
        int k;

        public QueryType3(int k) {
            super(3);
            this.k = k;
        }

        @Override
        public String toString() {
            return "3 " + k;
        }
    }

    class QueryType4 extends Query {

        public QueryType4() {
            super(4);
        }

        @Override
        public String toString() {
            return "4";
        }
    }

    class Test {
        int w, h;
        Query[] q;

        public Test(int w, int h, Query[] q) {
            this.w = w;
            this.h = h;
            this.q = q;
        }

        public String toString() {
            StringBuilder sb = new StringBuilder();
            sb.append(w + " " + h + "\n" + q.length + "\n");
            for (Query e : q) {
                sb.append(e + "\n");
            }
            return sb.toString();
        }
    }

    int testNum = 0;
    static Random rand = new Random(1);

    void printTest(Test test) {
        ++testNum;
        try {
            PrintWriter out = new PrintWriter("" + testNum / 10 + testNum % 10);
            out.print(test);
            out.close();
            System.err.println("Generated test #" + (testNum));
        } catch (Throwable e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int MAXN = 10000;

    void run() {
        printTest(new Test(10, 10, new Query[] {
                new QueryType1(2, 2, 8, 8, 3, 3), new QueryType4(),
                new QueryType1(0, 0, 5, 5, 5, 5), new QueryType3(1),
                new QueryType1(5, 5, 10, 10, 5, 5), new QueryType2(2),
                new QueryType4(), new QueryType3(3) }));
        printTest(new Test(100, 100, new Query[] {
                new QueryType1(5, 5, 5, 5, 5, 5),
                new QueryType1(5, 5, 5, 5, 5, 5), new QueryType4(),
                new QueryType3(1), new QueryType2(2), new QueryType4() }));
        for (int i = 2; i <= 16; i++) {
            printTest(genRandomTest((int) Math.pow(10, i / 2), (int) Math.pow(
                    10, i / 2), rand.nextBoolean() ? rand
                    .nextInt(i * MAXN / 15) : i * MAXN / 15));
        }
        for (int i = 2; i <= 16; i++) {
            printTest(genDotsTest((int) Math.pow(10, i / 2), (int) Math.pow(10,
                    i / 2), rand.nextBoolean() ? rand.nextInt(i * MAXN / 15)
                    : i * MAXN / 15));
        }
        for (int i = 2; i <= 16; i++) {
            printTest(genMaxTest((int) Math.pow(10, i / 2), (int) Math.pow(10,
                    i / 2), rand.nextBoolean() ? rand.nextInt(i * MAXN / 15)
                    : i * MAXN / 15));
        }
    }

    Test genDotsTest(int w, int h, int n) {
        Query[] q = new Query[n];
        int numOfAdded = 0;
        for (int i = 0; i < n; i++) {
            int type = numOfAdded == 0 ? rand.nextInt(2) * 3 : rand.nextInt(4);
            if (type == 0) {
                q[i] = getDotsQuery1(w, h);
                ++numOfAdded;
            } else if (type == 1) {
                q[i] = getRandomQuery2(numOfAdded);
            } else if (type == 2) {
                q[i] = getRandomQuery3(numOfAdded);
            } else {
                q[i] = getRandomQuery4();
            }
        }
        return new Test(w, h, q);
    }

    Test genMaxTest(int w, int h, int n) {
        Query[] q = new Query[n];
        int numOfAdded = 0;
        ArrayList<Integer> has = new ArrayList<Integer>();
        for (int i = 0; i < n; i++) {
            int type = numOfAdded == 0 ? rand.nextInt(2) * 3 : rand.nextInt(4);
            if (type == 0) {
                q[i] = getMaxQuery1(w, h);
                has.add(numOfAdded);
                ++numOfAdded;
            } else if (type == 1) {
                q[i] = has.size() == 0 ? getRandomQuery2(numOfAdded)
                        : getQuery2(has.get(has.size() - 1));
                if (has.size() != 0) {
                    has.remove(has.size() - 1);
                }
            } else if (type == 2) {
                q[i] = getRandomQuery3(numOfAdded);
            } else {
                q[i] = getRandomQuery4();
            }
        }
        return new Test(w, h, q);
    }

    Test genRandomTest(int w, int h, int n) {
        Query[] q = new Query[n];
        int numOfAdded = 0;
        for (int i = 0; i < n; i++) {
            int type = numOfAdded == 0 ? rand.nextInt(2) * 3 : rand.nextInt(4);
            if (type == 0) {
                int t2 = rand.nextInt(3);
                q[i] = t2 == 0 ? getRandomQuery1(w, h)
                        : t2 == 1 ? getMaxQuery1(w, h) : getDotsQuery1(w, h);
                ++numOfAdded;
            } else if (type == 1) {
                q[i] = getRandomQuery2(numOfAdded);
            } else if (type == 2) {
                q[i] = getRandomQuery3(numOfAdded);
            } else {
                q[i] = getRandomQuery4();
            }
        }
        return new Test(w, h, q);
    }

    QueryType1 getRandomQuery1(int w, int h) {
        int x1 = rand.nextInt(w - 1);
        int y1 = rand.nextInt(h - 1);
        int x2 = rand.nextInt(w - x1 + 1) + x1;
        int y2 = rand.nextInt(h - y1 + 1) + y1;
        int x = rand.nextInt(x2 - x1 + 1) + x1;
        int y = rand.nextInt(y2 - y1 + 1) + y1;
        return new QueryType1(x1, y1, x2, y2, x, y);
    }

    QueryType1 getDotsQuery1(int w, int h) {
        int x = rand.nextInt(w);
        int y = rand.nextInt(h);
        return new QueryType1(x, y, x, y, x, y);
    }

    QueryType1 getMaxQuery1(int w, int h) {
        int x1 = rand.nextInt(5);
        int y1 = rand.nextInt(5);
        int x2 = w - x1 - rand.nextInt(5) + x1;
        int y2 = h - y1 - rand.nextInt(5) + y1;
        int x = rand.nextInt(x2 - x1 + 1) + x1;
        int y = rand.nextInt(y2 - y1 + 1) + y1;
        return new QueryType1(x1, y1, x2, y2, x, y);
    }

    QueryType2 getRandomQuery2(int k) {
        return new QueryType2(rand.nextInt(k) + 1);
    }

    QueryType2 getQuery2(int k) {
        return new QueryType2(k + 1);
    }

    QueryType3 getRandomQuery3(int k) {
        return new QueryType3(rand.nextInt(k) + 1);
    }

    QueryType4 getRandomQuery4() {
        return new QueryType4();
    }
}
