import java.util.*; class Main { public static void main(String[] args) throws java.lang.Exception { final Scanner sc = new Scanner(System.in); final int n = sc.nextInt(); final int k = sc.nextInt(); final int[][] a = new int[n][]; for (int r = 0; r < n; r++) { a[r] = new int[n]; for (int c = 0; c < n; c++) { a[r][c] = sc.nextInt() - 1; } } final int[][] b = new int[n][]; for (int r = 0; r < n; r++) { b[r] = new int[n]; for (int c = 0; c < n; c++) { b[r][c] = sc.nextInt() - 1; } } final int[] ans = solve(n, k, a, b); System.out.println(ans.length); for (int op : ans) { if (op < n) { System.out.println("C " + (op+1)); } else { System.out.println("R " + (op+1-n)); } } } static int[] solve(final int n, final int k, final int[][] a, final int[][] b) { int[] ops = new int[k]; search(b, k, a, ops); List ans = new ArrayList<>(); int[][] t = deepcopy(a); for (int i = 0; i < k; i++) { final int op = ops[i]; final int[] v = op < n ? selectCol(t, op) : selectRow(t, op-n); if (op < n) { reorderColsByColPerm(t, op); } else { reorderRowsByRowPerm(t, op-n); } final List tmp = new ArrayList<>(); for (int cnt = cycle(v) - 1, z = op % n; cnt > 0; cnt--) { z = v[z]; tmp.add(op < n ? z : (z+n)); } ans.addAll(0, tmp); } return ans.stream().mapToInt(Integer::intValue).toArray(); } static void reorderColsByColPerm(final int[][] s, final int x) { int[][] t = deepcopy(s); for (int r = 0; r < s.length; r++) { for (int c = 0; c < s.length; c++) { s[ r ][ t[c][x] ] = t[r][c]; } } } static void reorderRowsByRowPerm(final int[][] s, final int y) { int[][] t = deepcopy(s); for (int r = 0; r < s.length; r++) { for (int c = 0; c < s.length; c++) { s[ t[y][r] ][ c ] = t[r][c]; } } } static int[] selectCol(final int[][] s, final int x) { return Arrays.stream(s).mapToInt(row -> row[x]).toArray(); } static int[] selectRow(final int[][] s, final int y) { return s[y].clone(); } static boolean search(final int[][] b, final int k, final int[][] t, final int[] v) { if (k == 0) { return Arrays.deepEquals(b, t); } for (int i = 0; i < b.length*2; i++) { v[k-1] = i; int[][] s = deepcopy(t); if (i < b.length) { reorderColsByColPerm(s, i); } else { reorderRowsByRowPerm(s, i - b.length); } if (search(b, k-1, s, v)) { return true; } } return false; } static int cycle(final int[] v) { int[] t = new int[v.length]; int[] w = v.clone(); for (int cnt = 1; ; cnt++) { for (int i = 0; i < v.length; i++) { t[ v[i] ] = w[i]; } if (Arrays.equals(t, v)) { return cnt; } int[] tmp = t; t = w; w = tmp; } } static int[][] deepcopy(final int[][] s) { return Arrays.stream(s).map(int[]::clone).toArray(int[][]::new); } }