/* Problem 6--15-Hole Peg Game
   The trickiest part was converting integer locations for the holes to
   row and column information.  After that, it was just brute force to
   look for jumps. */

import java.io.*;
import java.util.*;

public class prob6 {

 public static Scanner in;
 public static PrintStream out;
 public static int cs;
 public static boolean[][] T;

 public static void main (String[] args) throws Exception {

  in = new Scanner (new File ("prob6.in"));
  out = new PrintStream (new FileOutputStream ("prob6.out"));
  while (true) {
   String line = in.nextLine();
   T = new boolean[5][5];
   StringTokenizer ST = new StringTokenizer (line);
   while (ST.hasMoreTokens()) { //Read in the line of integers
    int i = Integer.parseInt (ST.nextToken());
    if (i==-1) System.exit (0);
    Position p = new Position (i);
    T[p.r][p.c] = true; //true means hole there; false means peg there
   }
   out.println ("Case "+(++cs));
   for (int i = 1; i <= 15; i++) {//iterate through all source positions
    Position pi = new Position (i);
    if (T[pi.r][pi.c]) continue; //build a list of all potential dests
    Position[] PA = {new Position(pi.r-2,pi.c-2),
                     new Position(pi.r-2,pi.c),
                     new Position(pi.r,pi.c-2),
                     new Position(pi.r,pi.c+2),
                     new Position(pi.r+2,pi.c),
                     new Position(pi.r+2,pi.c+2)};
    for (int j=0; j < 6; j++)
     if (PA[j].InBounds() && T[PA[j].r][PA[j].c] &&
         !T[(PA[j].r+pi.r)/2][(PA[j].c+pi.c)/2])
      out.println (i + " -> " + PA[j].geti()); //if valid jump print
   }
   out.println ();
  }
 }
}

/* class Position contains row and column information plus code to
   convert row and column information to and from the integer location*/
class Position {

 public int r, c;

 public Position (int r, int c) { //simple constructor

  this.r = r;
  this.c = c;
 }

 public Position (int i) { //convert from integer to row and column

  r = (int)((Math.sqrt (8*i-7)-1)/2);
  c = i - 1 - r*(r+1)/2;
 }

 public int geti () { //convert from row and column to integer

  return r*(r+1)/2 + c + 1;
 }

 public boolean InBounds () { //check whether a position is in bounds

  return r >=0 && r <= 4 && c >= 0 && c <= r;
 }
}