#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 /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int t, n, m, k, max_stones;
  scanf("%d", &t);
  while (t--) {
    max_stones = 0;
    scanf("%d%d%d", &n, &m, &k);
    if ((n == 1 && m == 1) || (n == 2 && m == 1) || (n == 1 && m == 2)) {
      max_stones = 0;
    } else if (n == 1 || m == 1) {
      max_stones = k;
    } else {
      max_stones += k / 2 + k % 2;
    }
    printf("%d\n", max_stones);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xece(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     121a <main+0xfa>
movl   $0x0,-0x18(%rbp)
lea    0xe9d(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x1,-0xc(%rbp)
jne    118a <main+0x6a>
cmpl   $0x1,-0x10(%rbp)
je     11b2 <main+0x92>
cmpl   $0x2,-0xc(%rbp)
jne    119e <main+0x7e>
cmpl   $0x1,-0x10(%rbp)
je     11b2 <main+0x92>
cmpl   $0x1,-0xc(%rbp)
jne    11be <main+0x9e>
cmpl   $0x2,-0x10(%rbp)
jne    11be <main+0x9e>
movl   $0x0,-0x18(%rbp)
jmp    1206 <main+0xe6>
cmpl   $0x1,-0xc(%rbp)
je     11d2 <main+0xb2>
cmpl   $0x1,-0x10(%rbp)
jne    11dd <main+0xbd>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1201 <main+0xe1>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x1c(%rbp),%eax
add    %edx,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1206 <main+0xe6>
mov    -0x18(%rbp),%esi
lea    0xdf7(%rip),%rdi
call   1030 <printf@plt>
jmp    1141 <main+0x21>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xecf(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subl   $0x1,0x8(%rsp)
jae    1159 <main+0x39>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xea0(%rip),%r14
lea    0x14(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r13
lea    0xe91(%rip),%rbx
jmp    1191 <main+0x71>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
subl   $0x1,0x8(%rsp)
jb     1148 <main+0x28>
xor    %ebp,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x14(%rsp),%ecx
mov    0x10(%rsp),%eax
cmp    $0x1,%ecx
jne    11b8 <main+0x98>
cmp    $0x1,%eax
je     1180 <main+0x60>
cmp    $0x2,%ecx
jne    11c2 <main+0xa2>
cmp    $0x1,%eax
je     1180 <main+0x60>
cmp    $0x1,%ecx
jne    11cc <main+0xac>
cmp    $0x2,%eax
je     1180 <main+0x60>
mov    0xc(%rsp),%ebp
cmp    $0x1,%ecx
je     1180 <main+0x60>
cmp    $0x1,%eax
je     1180 <main+0x60>
mov    %ebp,%eax
shr    $0x1f,%eax
add    %ebp,%eax
mov    %eax,%ecx
and    $0xfffffffe,%ecx
sub    %ecx,%ebp
sar    %eax
add    %eax,%ebp
jmp    1180 <main+0x60>

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [7 x i8] c"%d%d%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
%11 = add nsw i32 %10, -1
store i32 %11, i32* %1
%12 = icmp eq i32 %10, 0
br i1 %12, label %39, label %13
13: ; preds = %0, %33
%14 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 1
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, 1
%19 = select i1 %16, i1 %18, i1 false
br i1 %19, label %33, label %20
20: ; preds = %13
%21 = icmp eq i32 %15, 2
%22 = select i1 %21, i1 %18, i1 false
br i1 %22, label %33, label %23
23: ; preds = %20
%24 = icmp eq i32 %17, 2
%25 = select i1 %16, i1 %24, i1 false
br i1 %25, label %33, label %26
26: ; preds = %23
%27 = select i1 %16, i1 true, i1 %18
%28 = load i32, i32* %4
br i1 %27, label %33, label %29
29: ; preds = %26
%30 = sdiv i32 %28, 2
%31 = srem i32 %28, 2
%32 = add nsw i32 %30, %31
br label %33
33: ; preds = %26, %13, %20, %23, %29
%34 = phi i32 [ %32, %29 ], [ 0, %23 ], [ 0, %20 ], [ 0, %13 ], [ %28, %26 ]
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %1
%37 = add nsw i32 %36, -1
store i32 %37, i32* %1
%38 = icmp eq i32 %36, 0
br i1 %38, label %39, label %13
39: ; preds = %33, %0
ret i32 0
}