#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int min_cost(int, int, int **);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int T;
  scanf("%d", &T);
  for (int caseIndex = 1; caseIndex <= T; caseIndex++) {
    int N, M;
    scanf("%d %d", &N, &M);
    int C[300][300] = {};
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < M; j++) {
        scanf("%d", &C[i][j]);
      }
    }
    printf("Case #%d: %d\n", caseIndex, min_cost(N, M, C));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x57e70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1270 <main+0x130>
lea    0xe82(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1060 <scanf@plt>
lea    -0x57e60(%rbp),%rdi
xor    %esi,%esi
mov    $0x57e40,%edx
call   1040 <memset@plt>
movl   $0x0,-0x57e64(%rbp)
mov    -0x57e64(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1233 <main+0xf3>
movl   $0x0,-0x57e68(%rbp)
mov    -0x57e68(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    121a <main+0xda>
movslq -0x57e64(%rbp),%rax
lea    -0x57e60(%rbp),%rsi
imul   $0x4b0,%rax,%rax
add    %rax,%rsi
movslq -0x57e68(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x57e68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x57e68(%rbp)
jmp    11c3 <main+0x83>
jmp    121f <main+0xdf>
mov    -0x57e64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x57e64(%rbp)
jmp    11aa <main+0x6a>
mov    -0xc(%rbp),%eax
mov    %eax,-0x57e6c(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
lea    -0x57e60(%rbp),%rdx
call   1050 <min_cost@plt>
mov    -0x57e6c(%rbp),%esi
mov    %eax,%edx
lea    0xda9(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116b <main+0x2b>
xor    %eax,%eax
add    $0x57e70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x57e58,%rsp
lea    0xeab(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1235 <main+0xf5>
mov    $0x1,%ebx
lea    0x10(%rsp),%r13
lea    0xe83(%rip),%rbp
jmp    11b8 <main+0x78>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x10(%rsp),%r13
mov    %r13,%rdx
call   1050 <min_cost@plt>
lea    0xe62(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1030 <printf@plt>
lea    0x1(%rbx),%eax
cmp    0xc(%rsp),%ebx
mov    %eax,%ebx
jge    1235 <main+0xf5>
lea    0xe41(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    $0x57e40,%edx
mov    %r13,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    0x8(%rsp),%edi
mov    0x4(%rsp),%esi
test   %edi,%edi
jle    1190 <main+0x50>
xor    %r14d,%r14d
jmp    1203 <main+0xc3>
add    $0x1,%r14
movslq %edi,%rax
add    $0x4b0,%r13
cmp    %rax,%r14
jge    1190 <main+0x50>
test   %esi,%esi
jle    11f0 <main+0xb0>
mov    %r13,%r15
xor    %r12d,%r12d
nopl   (%rax)
mov    %rbp,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%r12
movslq 0x4(%rsp),%rsi
add    $0x4,%r15
cmp    %rsi,%r12
jl     1210 <main+0xd0>
mov    0x8(%rsp),%edi
jmp    11f0 <main+0xb0>
xor    %eax,%eax
add    $0x57e58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [14 x i8] c"Case #%d: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [300 x [300 x i32]]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 1, i32* %3
br label %10
10: ; preds = %49, %0
%11 = load i32, i32* %3
%12 = load i32, i32* %2
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %52
14: ; preds = %10
%15 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32* %5)
%16 = bitcast [300 x [300 x i32]]* %6 to i8*
store i32 0, i32* %7
br label %17
17: ; preds = %38, %14
%18 = load i32, i32* %7
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %41
21: ; preds = %17
store i32 0, i32* %8
br label %22
22: ; preds = %34, %21
%23 = load i32, i32* %8
%24 = load i32, i32* %5
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %37
26: ; preds = %22
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [300 x [300 x i32]], [300 x [300 x i32]]* %6, i64 0, i64 %28
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [300 x i32], [300 x i32]* %29, i64 0, i64 %31
%33 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %32)
br label %34
34: ; preds = %26
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
br label %22
37: ; preds = %22
br label %38
38: ; preds = %37
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %17
41: ; preds = %17
%42 = load i32, i32* %3
%43 = load i32, i32* %4
%44 = load i32, i32* %5
%45 = getelementptr inbounds [300 x [300 x i32]], [300 x [300 x i32]]* %6, i64 0, i64 0
%46 = bitcast [300 x i32]* %45 to i32**
%47 = call i32 @min_cost(i32 %43, i32 %44, i32** %46)
%48 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %42, i32 %47)
br label %49
49: ; preds = %41
%50 = load i32, i32* %3
%51 = add nsw i32 %50, 1
store i32 %51, i32* %3
br label %10
52: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [14 x i8] c"Case #%d: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [300 x [300 x i32]]
%5 = bitcast i32* %1 to i8*
%6 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 1
br i1 %8, label %14, label %9
9: ; preds = %0
%10 = bitcast i32* %2 to i8*
%11 = bitcast i32* %3 to i8*
%12 = bitcast [300 x [300 x i32]]* %4 to i8*
%13 = bitcast [300 x [300 x i32]]* %4 to i32**
br label %15
14: ; preds = %26, %0
ret i32 0
15: ; preds = %9, %26
%16 = phi i32 [ 1, %9 ], [ %31, %26 ]
%17 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
%18 = load i32, i32* %2
%19 = icmp sgt i32 %18, 0
%20 = load i32, i32* %3
br i1 %19, label %21, label %26
21: ; preds = %15, %36
%22 = phi i32 [ %37, %36 ], [ %18, %15 ]
%23 = phi i32 [ %38, %36 ], [ %20, %15 ]
%24 = phi i64 [ %39, %36 ], [ 0, %15 ]
%25 = icmp sgt i32 %23, 0
br i1 %25, label %42, label %36
26: ; preds = %36, %15
%27 = phi i32 [ %20, %15 ], [ %38, %36 ]
%28 = phi i32 [ %18, %15 ], [ %37, %36 ]
%29 = call i32 @min_cost(i32 %28, i32 %27, i32** %13)
%30 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %16, i32 %29)
%31 = add nuw nsw i32 %16, 1
%32 = load i32, i32* %1
%33 = icmp slt i32 %16, %32
br i1 %33, label %15, label %14
34: ; preds = %42
%35 = load i32, i32* %2
br label %36
36: ; preds = %34, %21
%37 = phi i32 [ %35, %34 ], [ %22, %21 ]
%38 = phi i32 [ %47, %34 ], [ %23, %21 ]
%39 = add nuw nsw i64 %24, 1
%40 = sext i32 %37 to i64
%41 = icmp slt i64 %39, %40
br i1 %41, label %21, label %26
42: ; preds = %21, %42
%43 = phi i64 [ %46, %42 ], [ 0, %21 ]
%44 = getelementptr inbounds [300 x [300 x i32]], [300 x [300 x i32]]* %4, i64 0, i64 %24, i64 %43
%45 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %44)
%46 = add nuw nsw i64 %43, 1
%47 = load i32, i32* %3
%48 = sext i32 %47 to i64
%49 = icmp slt i64 %46, %48
br i1 %49, label %42, label %34
}