cnt = 1
while gets
    n = $_.to_i
    break if n==0
    puts "Case #{cnt}:"
    arr = Array.new(n) { Array.new(n) }
    a = 1
    n.times do |i|
        if i % 2 == 0
            for j in 0..i
                arr[i-j][j] = a
                a += 1
            end
        else
            for j in 0..i
                arr[j][i-j] = a
                a += 1
            end
        end
    end
    a = n*n
    (n-1).times do |i|
        if i % 2 == 0
            for j in 0..i
                arr[n-i+j-1][n-j-1] = a
                a -= 1
            end
        else
            for j in 0..i
                arr[n-j-1][n-i+j-1] = a
                a -= 1
            end
        end
    end
    n.times do |i|
        puts arr[i].map{|j| "%3d".%(j)}.join("")
    end
    cnt += 1
end