import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines class Grid: def __init__(self, S): self.S = list(S) self.cnt = 0 self.log = [] def __repr__(self): return '\n'.join(''.join(self.S[4 * i:4 * i + 4]) for i in range(4)) def __getitem__(self, a): n = self.S.index(a) return divmod(n, 4) def shift_row(self, i, k): k %= 4 if k: self.log.append(f'R {i} {k}') A = self.S[4 * i:4 * i + 4] self.S[4 * i:4 * i + 4] = A[-k:] + A[:-k] def shift_col(self, i, k): k %= 4 if k: self.log.append(f'C {i} {k}') A = self.S[i::4] self.S[i::4] = A[-k:] + A[:-k] def move(G, a, n): """ n-1 以下のセルを固定したまま a を n に運ぶ """ r, c = divmod(n, 4) r1, c1 = G[a] if r == r1: # 一度同じ行から出す G.shift_col(c1, 1) k = 1 if (c1 + 1 - c) % 4 != 0 else 2 G.shift_row(r1 + 1, k) G.shift_col(c1, -1) r1, c1 = G[a] # 同じ列にあればよける if c == c1: G.shift_row(r1, 1) # 収納 r1, c1 = G[a] G.shift_col(c, r1 - r) G.shift_row(r1, (c - c1) % 4) G.shift_col(c, r - r1) def final_row(G): r, c = G['M'] G.shift_row(3, -c) A = ''.join(G.S[13:]) def fundamental_pattern(G, i, k): # 7 手で、最終行に偶置換 G.shift_col(i, 1) G.shift_row(3, k) G.shift_col(i, -1) G.shift_row(3, k + k) G.shift_col(i, 1) G.shift_row(3, k) G.shift_col(i, -1) if A == 'NOP': pass elif A == 'NPO': G.shift_row(3, 1) fundamental_pattern(G, 1, 1) elif A == 'ONP': G.shift_row(3, 1) fundamental_pattern(G, 0, 1) elif A == 'OPN': fundamental_pattern(G, 2, 3) elif A == 'PNO': fundamental_pattern(G, 2, 1) else: fundamental_pattern(G, 0, 1) G.shift_row(3, 1) fundamental_pattern(G, 2, 1) return S = ''.join(read().decode().split()) G = Grid(S) for n in range(12): a = chr(ord('A') + n) move(G, a, n) final_row(G) log = G.log print(len(log)) print('\n'.join(log))