import scala.annotation.tailrec
import scala.collection.{immutable, mutable}
object Main extends App {
  import scala.io.StdIn._
  loop()
  @tailrec def loop(caseCount: Int = 1): Unit = {
    val n = readInt()
    if (n == 0) return
    val state = Array.fill(n){Array.fill(n){0}}
    var count = 1
    for (d ← 0 until 2 * n) {
      val pos = math.max(0, d - n + 1) to math.min(d, n - 1)
      for (x ← if (d % 2 == 0) pos else pos.reverse) {
        state(d - x)(x) = count
        count += 1
      }
    }
    println(s"Case $caseCount:")
    println(state.map(_.map(it ⇒ f"$it%3d").mkString(sep = "")).mkString(sep = "\n"))
    loop(caseCount + 1)
  }
}
