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

public class TestGen {

	String[] test = {
			"6\n8\nsend 3 6\nback 3 6\nsend 3 5\nsend 3 3\nback 3 5\nsend 1 6\nback 1 6\nback 1 6\n8\nsend 2 2\nsend 3 3\nsend 1 6\nback 2 5\nsend 1 6\nback 1 5\nback 1 6\nback 1 6\n",
			"9\n8\nsend 6 7\nback 6 7\nsend 7 7\nsend 6 9\nsend 2 2\nback 1 4\nback 4 9\nback 1 9\n7\nsend 1 4\nsend 7 8\nrum\nback 4 9\nback 1 4\nsend 6 7\nback 1 9\n",
			"5\n9\nsend 4 5\nsend 3 5\nsend 1 4\nback 1 4\nsend 2 3\nrum\nback 3 5\nback 2 4\nback 1 5\n7\nsend 1 2\nsend 1 3\nback 1 4\nsend 2 4\nback 1 5\nrum\nback 1 5\n",
			"7\n5\nsend 2 4\nsend 1 2\nback 1 4\nrum\nback 1 7\n7\nsend 6 7\nback 3 7\nsend 2 4\nsend 2 4\nback 2 5\nback 2 7\nrum\n",
			"8\n8\nsend 3 4\nsend 3 3\nsend 3 6\nback 1 3\nsend 2 5\nback 2 6\nback 1 7\nback 2 8\n9\nsend 4 8\nsend 1 4\nrum\nback 4 8\nsend 2 3\nsend 7 8\nback 1 8\nback 3 8\nback 1 4\n",
			"9\n9\nsend 4 8\nsend 6 7\nback 1 9\nsend 1 2\nback 1 2\nback 4 9\nsend 6 9\nrum\nback 4 9\n7\nsend 2 7\nback 1 7\nsend 1 4\nrum\nsend 1 4\nback 1 5\nback 1 4\n",
			"5\n9\nrum\nsend 2 5\nsend 1 3\nsend 5 5\nback 1 3\nback 1 5\nback 3 5\nsend 3 3\nback 2 3\n7\nsend 1 1\nback 1 1\nsend 2 2\nsend 2 2\nrum\nback 1 3\nback 2 4\n",
			"17\n20\nsend 2 6\nsend 7 9\nsend 2 9\nback 3 16\nsend 4 17\nsend 4 15\nsend 4 6\nback 1 16\nback 3 16\nsend 6 7\nback 2 14\nsend 6 17\nsend 7 16\nback 3 17\nback 3 17\nback 4 15\nsend 4 9\nback 3 15\nback 3 11\nback 1 17\n23\nsend 10 17\nsend 8 9\nsend 3 8\nsend 9 17\nsend 7 14\nback 4 17\nsend 9 16\nback 5 17\nsend 4 12\nback 3 13\nrum\nsend 11 16\nback 5 16\nback 3 14\nsend 7 13\nsend 3 5\nback 2 17\nback 6 16\nsend 8 14\nback 8 17\nback 3 8\nback 1 13\nback 1 17\n",
			"29\n26\nsend 9 26\nsend 11 21\nsend 10 16\nsend 11 26\nback 6 26\nsend 17 27\nsend 7 19\nsend 7 16\nsend 2 28\nsend 6 11\nback 6 27\nsend 16 24\nback 2 26\nback 11 26\nback 2 29\nsend 2 24\nsend 12 22\nback 7 29\nsend 14 15\nback 1 29\nback 1 27\nback 12 24\nback 6 27\nback 1 28\nback 8 28\nback 1 29\n23\nsend 2 8\nsend 4 23\nsend 10 24\nsend 6 28\nback 3 29\nback 1 18\nsend 3 20\nsend 28 28\nback 1 27\nsend 7 17\nsend 14 26\nback 5 27\nsend 16 29\nsend 2 21\nback 5 28\nback 2 21\nback 15 29\nrum\nback 5 28\nsend 28 29\nback 2 26\nback 15 29\nback 1 29\n",
			"16\n18\nsend 11 16\nback 3 16\nsend 11 15\nback 5 15\nsend 6 10\nsend 6 11\nback 1 11\nsend 10 15\nsend 8 9\nsend 6 16\nback 6 15\nsend 3 12\nsend 8 14\nback 2 11\nback 1 14\nback 3 14\nback 1 16\nback 1 16\n28\nsend 8 10\nsend 9 10\nsend 3 16\nsend 5 9\nback 1 16\nsend 2 9\nsend 2 15\nsend 4 15\nback 4 15\nsend 7 11\nback 1 16\nsend 7 15\nback 1 12\nsend 14 14\nsend 10 13\nback 7 16\nsend 8 10\nback 9 14\nback 1 15\nsend 3 12\nback 1 10\nback 6 16\nback 2 16\nback 3 12\nsend 12 14\nback 2 14\nback 6 16\nback 1 16\n" };

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

	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}
		return in.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	int tNumber;

	Random rnd;

	int n;

	void print(int n, Plan pl1, Plan pl2) throws IOException {

		if (tNumber < 10) {
			out = new PrintWriter("../tests/0" + tNumber);
		} else {
			out = new PrintWriter("../tests/" + tNumber);
		}
		pl1.queries[pl1.m - 1] = "back";
		pl2.queries[pl2.m - 1] = "back";
		pl1.l[pl1.m - 1] = 1;
		pl2.l[pl2.m - 1] = 1;
		pl1.r[pl1.m - 1] = n;
		pl2.r[pl2.m - 1] = n;

		tNumber++;
		out.println(n);
		out.println(pl1.m);
		for (int i = 0; i < pl1.m; i++) {
			out.print(pl1.queries[i]);
			if (pl1.queries[i].equals("rum")) {
				out.println();
			} else {
				out.println(" " + pl1.l[i] + " " + pl1.r[i]);
			}
		}
		out.println(pl2.m);
		for (int i = 0; i < pl2.m; i++) {
			out.print(pl2.queries[i]);
			if (pl2.queries[i].equals("rum")) {
				out.println();
			} else {
				out.println(" " + pl2.l[i] + " " + pl2.r[i]);
			}
		}

		out.close();
	}

	void genSimple() throws IOException {
		PrintWriter out;
		out = new PrintWriter("../preliminary/01");
		out.println("3");
		out.println("4");
		out.println("send 1 1");
		out.println("send 2 2");
		out.println("back 1 1");
		out.println("back 1 3");
		out.println("5");
		out.println("send 2 3");
		out.println("send 1 1");
		out.println("back 2 2");
		out.println("rum");
		out.println("back 1 3");
		out.close();
	}

	class Plan {
		String[] queries;
		int[] l;
		int[] r;
		int m;

		public Plan(int m) {
			this.m = m;
			queries = new String[m];
			l = new int[m];
			r = new int[m];
		}
	}

	void print1(int n, int m1, int m2) throws IOException {
		Plan pl1 = new Plan(m1);
		Plan pl2 = new Plan(m2);
		for (int i = 0; i < pl1.m; i++) {
			int t = rnd.nextInt(3);
			if (t == 0) {
				pl1.queries[i] = "rum";
			}
			if (t == 1) {
				pl1.queries[i] = "send";
			}
			if (t == 2) {
				pl1.queries[i] = "back";
			}
			pl1.l[i] = 1;
			pl1.r[i] = n;
		}
		for (int i = 0; i < pl2.m; i++) {
			int t = rnd.nextInt(3);
			if (t == 0) {
				pl2.queries[i] = "rum";
			}
			if (t == 1) {
				pl2.queries[i] = "send";
			}
			if (t == 2) {
				pl2.queries[i] = "back";
			}
			pl2.l[i] = 1;
			pl2.r[i] = n;
		}
		print(n, pl1, pl2);
	}

	void printrum(int n, int m1, int m2) throws IOException {
		Plan pl1 = new Plan(m1);
		Plan pl2 = new Plan(m2);
		for (int i = 0; i < pl1.m; i++) {
			pl1.queries[i] = "rum";
		}
		for (int i = 0; i < pl2.m; i++) {
			pl2.queries[i] = "rum";
		}
		print(n, pl1, pl2);
	}

	void readPlan(Plan pl, Scanner in) throws IOException {
		for (int i = 0; i < pl.m; i++) {
			pl.queries[i] = in.next();
			if (!pl.queries[i].equals("rum")) {
				pl.l[i] = in.nextInt();
				pl.r[i] = in.nextInt();
			}
		}
	}

	Plan[] parsePlans(String s) throws IOException {
		Scanner in = new Scanner(s);
		n = in.nextInt();
		Plan pl1 = new Plan(in.nextInt());
		readPlan(pl1, in);
		Plan pl2 = new Plan(in.nextInt());
		readPlan(pl2, in);
		Plan[] pl = new Plan[2];
		pl[0] = pl1;
		pl[1] = pl2;
		return pl;
	}

	void genshort() throws IOException {
		for (int i = 0; i < 7; i++) {
			Plan[] pl = parsePlans(test[i]);
			print(n, pl[0], pl[1]);
		}
		print1(1, 10, 10);
		printrum(10, 10, 10);
		print1(10, 10, 10);
	}

	void obfuscate(int corr, int n, Plan p0, Plan p1) {
		HashSet<Integer> hsh = new HashSet<>();
		hsh.add(1);
		hsh.add(corr);
		int[] a = new int[n];
		a[0] = 1;
		a[1] = corr;
		for (int i = 0; i < n - 2; i++) {
			int c = rnd.nextInt(corr) + 1;
			while (hsh.contains(c)) {
				c = rnd.nextInt(corr) + 1;
			}
			a[i + 2] = c;
			hsh.add(c);
		}
		Arrays.sort(a);
		for (int i = 0; i < p0.m; i++) {
			if (p0.l[i] != 0) {
				p0.l[i] = a[p0.l[i] - 1];
			}
			if (p0.r[i] != 0) {
				p0.r[i] = a[p0.r[i] - 1];
			}
		}
		for (int i = 0; i < p1.m; i++) {
			if (p1.l[i] != 0) {
				p1.l[i] = a[p1.l[i] - 1];
			}
			if (p1.r[i] != 0) {
				p1.r[i] = a[p1.r[i] - 1];
			}
		}

	}

	void generate(int upc, int upn) throws IOException {
		Plan p1 = new Plan(upn);
		Plan p2 = new Plan(upn);
		int curn = 0;
		int curm = 0;
		while (true) {
			Plan[] plans = parsePlans(test[rnd.nextInt(test.length)]);
			if (rnd.nextBoolean()) {
				Plan t = plans[0];
				plans[0] = plans[1];
				plans[1] = t;
			}
			obfuscate(upc, n, plans[0], plans[1]);
			if (curn + plans[0].m > upn) {
				break;
			}
			if (curm + plans[1].m > upn) {
				break;
			}
			for (int i = 0; i < plans[0].m; i++) {
				p1.queries[curn] = plans[0].queries[i];
				p1.l[curn] = plans[0].l[i];
				p1.r[curn] = plans[0].r[i];
				curn++;
			}

			for (int i = 0; i < plans[1].m; i++) {
				p2.queries[curm] = plans[1].queries[i];
				p2.l[curm] = plans[1].l[i];
				p2.r[curm] = plans[1].r[i];
				curm++;
			}
		}
		p1.m = curn;
		p2.m = curm;
		print(upc, p1, p2);
	}

	void genTests(int upc, int upm) throws IOException {
		for (int i = 0; i < 7; i++) {
			generate(upc, upm);
		}
		print1(1, upm, upm);
		print1(upc, upm, upm);
		printrum(upc, upm, upm);
	}

	public void generate() throws IOException {
		new File("../preliminary").mkdir();
		new File("../tests").mkdir();
		tNumber = 1;
		rnd = new Random(3);
		genSimple();
		genshort();
		genTests(300, 300);
		genTests(1000, 1000);
		genTests(1000000000, 3000);
	}

	public void run() {
		try {
			generate();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}
