import sys # sys.setrecursionlimit(200005) # sys.set_int_max_str_digits(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = -1-(-1 << 31) inf = -1-(-1 << 62) # md = 10**9+7 # md = 998244353 from math import lcm def size(rep): fin=[0]*n l=1 for i in range(n): if fin[i]:continue s=0 while fin[i]==0: fin[i]=1 s+=1 i=rep[i] l=lcm(l,s) return l def dfs(toi,toj,op,cnt): if cnt: for i in range(n): rep=[0]*n for nj,a in zip(toj,aa[i]):rep[nj]=a res=dfs([rep[t] for t in toi],toj,op+[toi[i]*2],cnt-1) if res: res[1].append(size(rep)) return res for j in range(n): rep=[0]*n for i in range(n): ni=toi[i] rep[ni]=aa[i][j] res=dfs(toi,[rep[t] for t in toj],op+[toj[j]*2+1],cnt-1) if res: res[1].append(size(rep)) return res return None for i in range(n): for j in range(n): ni=toi[i] nj=toj[j] if aa[i][j]!=bb[ni][nj]:return None return op[::-1],[] n,k=LI() aa=LLI1(n) bb=LLI1(n) op,ll=dfs(list(range(n)),list(range(n)),[],k) print(sum(ll)-k) for p,l in zip(op,ll): c="RC"[p&1]+" "+str(p//2+1) for _ in range(l-1): print(c)