def change(A,com,ind): if com=="R": A2=[] for i in range(N): A2.append(A[i*N:i*N+N]) C=[[] for i in range(N)] for j in range(N): C[A2[ind-1][j]-1]=A2[j] D=[] for i in range(N): for x in C[i]: D.append(x) return D else: B=[] for i in range(N): for j in range(N): B.append(A[j*N+i]) #print(B) B2=[] for i in range(N): B2.append(B[i*N:i*N+N]) C=[[] for i in range(N)] for j in range(N): C[B2[ind-1][j]-1]=B2[j] D=[] for i in range(N): for x in C[i]: D.append(x) E=[] for i in range(N): for j in range(N): E.append(D[j*N+i]) return E N,K=map(int,input().split()) A=[] for i in range(N): A+=list(map(int,input().split())) A0=tuple(A) B=[] for i in range(N): B+=list(map(int,input().split())) DICT=dict() DICT[tuple(A)]=[] FROM=dict() Q=[tuple(A)] for i in range(4): #print(i,len(Q)) NQ=[] while Q: A=Q.pop() ANS=DICT[A] for ind in range(1,N+1): A2=change(A,"R",ind) if tuple(A2) in DICT: pass else: ANS2=ANS+[["R",ind]] DICT[tuple(A2)]=ANS2 FROM[tuple(A2)]=(tuple(A),"R",ind) NQ.append(tuple(A2)) A2=change(A,"C",ind) if tuple(A2) in DICT: pass else: ANS2=ANS+[["R",ind]] DICT[tuple(A2)]=ANS2 FROM[tuple(A2)]=(tuple(A),"C",ind) NQ.append(tuple(A2)) Q=NQ B=tuple(B) ANS=[] while B!=tuple(A0): #print("!!",B) fr,com,ind=FROM[B] #print(B,fr,com,ind) if com=="R": fr2=[] for i in range(N): fr2.append(fr[i*N:i*N+N]) need=fr2[ind-1] #print(need) while tuple(B)!=tuple(fr): #print(B) B2=[] for i in range(N): B2.append(B[i*N:i*N+N]) #print(B2) for i in range(N): if B2[i]==tuple(need): ANS.append(("R",i+1)) B=change(B,"R",i+1) break B=tuple(B) B=tuple(B) else: B2=[] for i in range(N): for j in range(N): B2.append(B[j*N+i]) fr2=[] for i in range(N): for j in range(N): fr2.append(fr[j*N+i]) B=B2 fr=fr2 fr2=[] for i in range(N): fr2.append(fr[i*N:i*N+N]) need=fr2[ind-1] while tuple(B)!=tuple(fr): #print(B,need) B2=[] for i in range(N): B2.append(B[i*N:i*N+N]) for i in range(N): if B2[i]==tuple(need): ANS.append(("C",i+1)) B=change(B,"R",i+1) break B=tuple(B) B2=[] for i in range(N): for j in range(N): B2.append(B[j*N+i]) B=tuple(B2) print(len(ANS)) for com,ind in ANS: print(com,ind)