#include <bits/stdc++.h>

using namespace std;

int main()
{
	srand(time(0));
	int T = 10;
	int n = 10000;
	int Q = 20000;
	int m = 223092870;
	printf("%d\n", T);
	while (T--) {
		printf("%d %d\n", n, m);
		for (int i = 1; i <= n; i++) {
			printf("%d ", 1);
		}
		puts("");
		printf("%d\n", Q);
		for (int i = 0; i < Q; i++) {
			int op = rand() % 2;
			if (op == 0) {
				int L = rand() % n + 1;
				int R = rand() % n + 1;
				if (L > R) swap(L, R);
				printf("Q %d %d\n", L, R);
			}
			if (op == 1) {
				int L = rand() % n + 1;
				int R = rand() % n + 1;
				if (L > R) swap(L, R);
				int x = rand() % 10 + 1;
				printf("M %d %d %d\n", L, R, x);
			}
		}
	}
	return 0;
}
