#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*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, ...);
int /*<<< orphan*/ simulateWar(char **, char **, int, int, int);
int main(void) {
  int T, numRow, numCol, numDay, row;
  char grid[100][100 + 1], result[100][100 + 1], trash[100 + 1];
  scanf("%d", &T);
  while (T) {
    scanf("%d %d %d", &numRow, &numCol, &numDay);
    gets(trash);
    for (row = 0; row < numRow; row++)
      gets(grid[row]);
    simulateWar(grid, result, numRow, numCol, numDay);
    for (row = 0; row < numRow; row++)
      printf("%s\n", result[row]);
    if (T != 1)
      printf("\n");
    T--;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4f80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xead(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
je     1250 <main+0x110>
lea    0xe8b(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
mov    $0x0,%al
call   1060 <scanf@plt>
lea    -0x4f80(%rbp),%rdi
call   1040 <gets@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11cc <main+0x8c>
movslq -0x18(%rbp),%rax
lea    -0x2790(%rbp),%rdi
imul   $0x65,%rax,%rax
add    %rax,%rdi
call   1040 <gets@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119b <main+0x5b>
lea    -0x2790(%rbp),%rdi
lea    -0x4f10(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
call   1050 <simulateWar@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    122a <main+0xea>
movslq -0x18(%rbp),%rax
lea    -0x4f10(%rbp),%rsi
imul   $0x65,%rax,%rax
add    %rax,%rsi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11f0 <main+0xb0>
cmpl   $0x1,-0x8(%rbp)
je     1242 <main+0x102>
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1164 <main+0x24>
xor    %eax,%eax
add    $0x4f80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4f78,%rsp
lea    0xe9e(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
je     1245 <main+0xf5>
lea    0x10(%rsp),%r13
lea    0x2800(%rsp),%r12
lea    0x80(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xe59(%rip),%rdi
mov    %rsp,%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
xor    %eax,%eax
call   1070 <scanf@plt>
mov    %r13,%rdi
call   1050 <gets@plt>
mov    (%rsp),%edx
test   %edx,%edx
jle    11e9 <main+0x99>
mov    %r12,%rbp
xor    %ebx,%ebx
nop
mov    %rbp,%rdi
call   1050 <gets@plt>
add    $0x1,%rbx
movslq (%rsp),%rdx
add    $0x65,%rbp
cmp    %rdx,%rbx
jl     11d0 <main+0x80>
mov    0xc(%rsp),%ecx
mov    0x8(%rsp),%r8d
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <simulateWar@plt>
cmpl   $0x0,(%rsp)
jle    1229 <main+0xd9>
mov    %r15,%r14
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <puts@plt>
add    $0x1,%rbp
movslq (%rsp),%rax
add    $0x65,%r14
cmp    %rax,%rbp
jl     1210 <main+0xc0>
cmpl   $0x1,0x4(%rsp)
je     1245 <main+0xf5>
mov    $0xa,%edi
call   1030 <putchar@plt>
addl   $0xffffffff,0x4(%rsp)
jne    11a0 <main+0x50>
xor    %eax,%eax
add    $0x4f78,%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 = [9 x i8] c"%d %d %d\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [100 x [101 x i8]]
%8 = alloca [100 x [101 x i8]]
%9 = alloca [101 x i8]
store i32 0, i32* %1
%10 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %11
11: ; preds = %58, %0
%12 = load i32, i32* %2
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %61
14: ; preds = %11
%15 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%16 = getelementptr inbounds [101 x i8], [101 x i8]* %9, i64 0, i64 0
%17 = call i32 @gets(i8* %16)
store i32 0, i32* %6
br label %18
18: ; preds = %28, %14
%19 = load i32, i32* %6
%20 = load i32, i32* %3
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %31
22: ; preds = %18
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [100 x [101 x i8]], [100 x [101 x i8]]* %7, i64 0, i64 %24
%26 = getelementptr inbounds [101 x i8], [101 x i8]* %25, i64 0, i64 0
%27 = call i32 @gets(i8* %26)
br label %28
28: ; preds = %22
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %18
31: ; preds = %18
%32 = getelementptr inbounds [100 x [101 x i8]], [100 x [101 x i8]]* %7, i64 0, i64 0
%33 = bitcast [101 x i8]* %32 to i8**
%34 = getelementptr inbounds [100 x [101 x i8]], [100 x [101 x i8]]* %8, i64 0, i64 0
%35 = bitcast [101 x i8]* %34 to i8**
%36 = load i32, i32* %3
%37 = load i32, i32* %4
%38 = load i32, i32* %5
%39 = call i32 @simulateWar(i8** %33, i8** %35, i32 %36, i32 %37, i32 %38)
store i32 0, i32* %6
br label %40
40: ; preds = %50, %31
%41 = load i32, i32* %6
%42 = load i32, i32* %3
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %53
44: ; preds = %40
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [100 x [101 x i8]], [100 x [101 x i8]]* %8, i64 0, i64 %46
%48 = getelementptr inbounds [101 x i8], [101 x i8]* %47, i64 0, i64 0
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %44
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 1
store i32 %52, i32* %6
br label %40
53: ; preds = %40
%54 = load i32, i32* %2
%55 = icmp ne i32 %54, 1
br i1 %55, label %56, label %58
56: ; preds = %53
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %58
58: ; preds = %56, %53
%59 = load i32, i32* %2
%60 = add nsw i32 %59, -1
store i32 %60, i32* %2
br label %11
61: ; preds = %11
ret i32 0
}

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