#include <stdio.h>

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int cn;

  for ( cn = 1; ; ++cn )
  {
    int n;

    scanf ( "%d", &n );
    if ( !( n ) ) break ;

    printf ( "Case %d:\n", cn );
    switch ( n )
    {
      case 1:
        puts ( "  1" );
        break ;
      case 2:
        puts ( "  1  2" );
        puts ( "  3  4" );
        break ;
      case 3:
        puts ( "  1  2  6" );
        puts ( "  3  5  7" );
        puts ( "  4  8  9" );
        break ;
      case 4:
        puts ( "  1  2  6  7" );
        puts ( "  3  5  8 13" );
        puts ( "  4  9 12 14" );
        puts ( " 10 11 15 16" );
        break;
      case 5:
        puts ( "  1  2  6  7 15" );
        puts ( "  3  5  8 14 16" );
        puts ( "  4  9 13 17 22" );
        puts ( " 10 12 18 21 23" );
        puts ( " 11 19 20 24 25" );
        break;
      case 6:
        puts ( "  1  2  6  7 15 16" );
        puts ( "  3  5  8 14 17 26" );
        puts ( "  4  9 13 18 25 27" );
        puts ( " 10 12 19 24 28 33" );
        puts ( " 11 20 23 29 32 34" );
        puts ( " 21 22 30 31 35 36" );
        break;
      case 7:
        puts ( "  1  2  6  7 15 16 28" );
        puts ( "  3  5  8 14 17 27 29" );
        puts ( "  4  9 13 18 26 30 39" );
        puts ( " 10 12 19 25 31 38 40" );
        puts ( " 11 20 24 32 37 41 46" );
        puts ( " 21 23 33 36 42 45 47" );
        puts ( " 22 34 35 43 44 48 49" );
        break;
      case 8:
        puts ( "  1  2  6  7 15 16 28 29" );
        puts ( "  3  5  8 14 17 27 30 43" );
        puts ( "  4  9 13 18 26 31 42 44" );
        puts ( " 10 12 19 25 32 41 45 54" );
        puts ( " 11 20 24 33 40 46 53 55" );
        puts ( " 21 23 34 39 47 52 56 61" );
        puts ( " 22 35 38 48 51 57 60 62" );
        puts ( " 36 37 49 50 58 59 63 64" );
        break;
      case 9:
        puts ( "  1  2  6  7 15 16 28 29 45" );
        puts ( "  3  5  8 14 17 27 30 44 46" );
        puts ( "  4  9 13 18 26 31 43 47 60" );
        puts ( " 10 12 19 25 32 42 48 59 61" );
        puts ( " 11 20 24 33 41 49 58 62 71" );
        puts ( " 21 23 34 40 50 57 63 70 72" );
        puts ( " 22 35 39 51 56 64 69 73 78" );
        puts ( " 36 38 52 55 65 68 74 77 79" );
        puts ( " 37 53 54 66 67 75 76 80 81" );
        break;
    }
  }

  return ( 0 );
}