#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*/ challenge(char **, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    char **matrix;
    matrix = (char **)malloc(n * sizeof(char *));
    int i;
    for (i = 0; i < n; i++) {
      matrix[i] = (char *)malloc(n * sizeof(char));
      scanf("%s", matrix[i]);
    }
    challenge(matrix, n);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     11f4 <main+0xc4>
lea    0xe94(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e3 <main+0xb3>
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1191 <main+0x61>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <challenge@plt>
jmp    1151 <main+0x21>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xebc(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
subl   $0x1,0xc(%rsp)
jae    1167 <main+0x37>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe92(%rip),%r14
lea    0x8(%rsp),%r15
lea    0xe89(%rip),%r12
jmp    118f <main+0x5f>
nopl   0x0(%rax)
mov    %r13,%rdi
call   1030 <challenge@plt>
subl   $0x1,0xc(%rsp)
jb     1157 <main+0x27>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x8(%rsp),%edi
shl    $0x3,%edi
call   1040 <malloc@plt>
mov    %rax,%r13
mov    0x8(%rsp),%esi
test   %esi,%esi
jle    1180 <main+0x50>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %esi,%edi
call   1040 <malloc@plt>
mov    %rax,0x0(%r13,%rbx,8)
mov    %r12,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rsi
cmp    %rsi,%rbx
jl     11c0 <main+0x90>
jmp    1180 <main+0x50>

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

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