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

public class TestsGen {

    int testCount;

    void write(String s) throws IOException {
        PrintWriter pw = new PrintWriter(String.format("../tests/%02d", ++testCount));
        System.out.println(testCount);
        pw.println(s);
        pw.close();
    }
    
    void write(int n) throws IOException {
        write(Integer.toString(n));
    }

    Random random = new Random(43534543);

    void write(int n, int m, String[] s) throws IOException {
        StringBuilder res = new StringBuilder();
        res.append(Integer.toString(n) + " " + Integer.toString(m) + "\r\n");
        for (int i = 0; i < m; i++) {
            res.append(s[i]);
            if (i + 1 < m) res.append("\r\n");
        }
        write(res.toString());
    }

    void genRand(int n, int m, int a1, int a2, int a3) throws IOException {
        String[] res = new String[m];
        int cnt = 0, alive = 0;
        int ll[] = new int[m], rr[] = new int[m];
        for (int i = 0; i < m; i++) {
            ll[i] = i - 1;
            rr[i] = i + 1;
        }
        for (int i = 0; i < m; i++) {
            while (true) {
                int t = random.nextInt(a1 + a2 + a3);
                if (0 <= t && t < a1) {
                    int l = random.nextInt(n) + 1;
                    int r = random.nextInt(n - l + 1) + l;
                    int x = random.nextInt((int)1e9);
                    res[i] = "A " + Integer.toString(l) + " " + Integer.toString(r) + " " + Integer.toString(x);
                    alive++;
                    cnt++;
                }
                if (a1 <= t && t < a1 + a2) {
                    int id = random.nextInt(n) + 1;
                    res[i] = "G " + Integer.toString(id);
                }
                if (a1 + a2 <= t && t < a1 + a2 + a3) {
                    if (alive == 0) continue;
                    int x = ll[cnt];
                    int oth = alive;
                    while (true) {
                        if (oth == 1 || random.nextInt(3) == 0) {
                            break;
                        } else {
                            x = ll[x];
                            oth--;
                        }
                    }
                    ll[rr[x]] = ll[x];
                    if (ll[x] != -1) {
                        rr[ll[x]] = rr[x];
                    }
                    alive--;
                    res[i] = "R " + Integer.toString(x + 1);
                }
                break;
            }
        }
        write(n, m, res);
    }

    void genMax(boolean f) throws IOException {
        int n = 100000;
        int m = 100000;
        String res[] = new String[m];
        int j = 0;
        int l[] = new int[m];
        int r[] = new int[m];
        for (int i = 0; i < m / 3; i++) {
            l[i] = i - 1;
            r[i] = i + 1;
            res[j++] = "A 1 99999 " + Integer.toString(random.nextInt((int)1e9));
        }
        int o = j;
        l[o] = j - 1;
        int alive = m / 3;
        for (int i = 0; i < m / 3; i++) {
            res[j++] = "G " + Integer.toString(random.nextInt(n) + 1);
            int x = l[o];
            int calive = alive;
            while (true) {
                if (calive == 1 || random.nextInt(3) == 0) {
                    break;
                }
                x = l[x];
                calive--;
            }
            if (f) x = i;
            alive--;
            res[j++] = "R " + Integer.toString(x + 1);
            l[r[x]] = l[x];
            if (l[x] != -1) r[l[x]] = r[x];
        }
        res[j++] = "G " + Integer.toString(random.nextInt(n) + 1);
        write(n, m, res);
    }

    void run() throws IOException {
        new File("../tests").mkdir();
            
        write("3 7\r\nA 1 3 5\r\nA 2 3 3\r\nG 1\r\nG 2\r\nR 1\r\nG 1\r\nG 2");
        
        genRand(5, 10, 1, 1, 1);
        genRand(10, 20, 1, 1, 1);
        genRand(20, 50, 1, 1, 1);
        genRand(50, 100, 1, 1, 1);
        genRand(100, 200, 1, 1, 1);
        genRand(5453, 1234, 1, 1, 1);
        genRand(42524, 77753, 1, 1, 1);
        genRand(100000, 100000, 1, 1, 1);
        genRand(100000, 100000, 2, 3, 1);
        genRand(100000, 100000, 1, 1, 5);
        genRand(100000, 100000, 10, 2, 3);
        genRand(100000, 100000, 10, 2, 1);
        for (int i = 0; i < 20; i++) {
            genRand(100000, 100000, random.nextInt(20) + 1, random.nextInt(20) + 1, random.nextInt(20) + 1);
        }       
        genMax(false);
        genMax(true);
    }

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

}
