#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 getMinSizeSquareSum(int, int *);
int /*<<< orphan*/ memset(int *, int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int memoTable[10000 + 1], T, n;
  memset(memoTable, -1, (10000 + 1) * sizeof(int));
  scanf("%d", &T);
  while (T) {
    scanf("%d", &n);
    printf("%d\n", getMinSizeSquareSum(n, memoTable));
    T--;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c60,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x9c50(%rbp),%rdi
mov    $0xffffffff,%esi
mov    $0x9c44,%edx
call   1040 <memset@plt>
lea    0xe91(%rip),%rdi
lea    -0x9c54(%rbp),%rsi
call   1060 <scanf@plt>
cmpl   $0x0,-0x9c54(%rbp)
je     11cf <main+0x8f>
lea    0xe71(%rip),%rdi
lea    -0x9c58(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x9c58(%rbp),%edi
lea    -0x9c50(%rbp),%rsi
call   1050 <getMinSizeSquareSum@plt>
mov    %eax,%esi
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x9c54(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x9c54(%rbp)
jmp    117b <main+0x3b>
xor    %eax,%eax
add    $0x9c60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x9c58,%rsp
lea    0x10(%rsp),%rdi
mov    $0xffffffff,%esi
mov    $0x9c44,%edx
call   1040 <memset@plt>
lea    0xe97(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
je     11c8 <main+0x88>
lea    0xe7f(%rip),%r14
lea    0xc(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xe71(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%edi
mov    %r12,%rsi
call   1050 <getMinSizeSquareSum@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
addl   $0xffffffff,0x8(%rsp)
jne    11a0 <main+0x60>
xor    %eax,%eax
add    $0x9c58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10001 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = getelementptr inbounds [10001 x i32], [10001 x i32]* %2, i64 0, i64 0
%6 = call i32 @memset(i32* %5, i32 -1, i32 40004)
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
br label %8
8: ; preds = %11, %0
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%13 = load i32, i32* %4
%14 = getelementptr inbounds [10001 x i32], [10001 x i32]* %2, i64 0, i64 0
%15 = call i32 @getMinSizeSquareSum(i32 %13, i32* %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %3
%18 = add nsw i32 %17, -1
store i32 %18, i32* %3
br label %8
19: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [10001 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = bitcast [10001 x i32]* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [10001 x i32], [10001 x i32]* %1, i64 0, i64 0
%8 = call i32 @memset(i32* %7, i32 -1, i32 40004)
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %0, %12
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%14 = load i32, i32* %3
%15 = call i32 @getMinSizeSquareSum(i32 %14, i32* %7)
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %2
%18 = add nsw i32 %17, -1
store i32 %18, i32* %2
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %12
20: ; preds = %12, %0
ret i32 0
}