#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*/ free(int *);
int getSumOfArray(int *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(int *, int, int);
int /*<<< orphan*/ partition(int *, int, int /*<<< orphan*/, int, int *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int t, j = 0;
  int *arr;
  int n;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    arr = (int *)malloc(n * sizeof(int *));
    for (j = 0; j < n; j++) {
      scanf("%d", &arr[j]);
    }
    int *brr = (int *)malloc(sizeof(int) * n);
    memset(brr, 1, sizeof(int) * n);
    partition(arr, n, 0, n - 1, brr);
    printf("%d\n", getSumOfArray(brr, n));
    free(arr);
    free(brr);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe73(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     127d <main+0x10d>
lea    0xe4f(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1090 <scanf@plt>
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1209 <main+0x99>
mov    -0x18(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe0a(%rip),%rdi
call   1090 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d4 <main+0x64>
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
mov    $0x1,%esi
call   1060 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x28(%rbp),%r8
xor    %edx,%edx
call   1040 <partition@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1070 <getSumOfArray@plt>
mov    %eax,%esi
lea    0xda2(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    1196 <main+0x26>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe7e(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1090 <scanf@plt>
subl   $0x1,0x4(%rsp)
jae    11a4 <main+0x34>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe55(%rip),%r14
lea    0xe51(%rip),%r15
jmp    1221 <main+0xb1>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
shl    $0x2,%edi
call   1080 <malloc@plt>
mov    %rax,%r13
mov    (%rsp),%edx
shl    $0x2,%edx
mov    %rax,%rdi
mov    $0x1,%esi
call   1060 <memset@plt>
mov    (%rsp),%esi
lea    -0x1(%rsi),%ecx
mov    %r12,%rdi
xor    %edx,%edx
mov    %r13,%r8
call   1040 <partition@plt>
mov    (%rsp),%esi
mov    %r13,%rdi
call   1070 <getSumOfArray@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
subl   $0x1,0x4(%rsp)
jb     1193 <main+0x23>
mov    %r14,%rdi
mov    %rsp,%rsi
call   1090 <scanf@plt>
mov    (%rsp),%edi
shl    $0x3,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
mov    (%rsp),%edi
test   %edi,%edi
jle    11c0 <main+0x50>
mov    %r12,%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <scanf@plt>
add    $0x1,%rbp
movslq (%rsp),%rdi
add    $0x4,%rbx
cmp    %rdi,%rbp
jl     1250 <main+0xe0>
jmp    11c0 <main+0x50>

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 i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %3
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %8
8: ; preds = %33, %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 %60
12: ; preds = %8
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 8
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i32*
store i32* %19, i32** %4
store i32 0, i32* %3
br label %20
20: ; preds = %30, %12
%21 = load i32, i32* %3
%22 = load i32, i32* %5
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %33
24: ; preds = %20
%25 = load i32*, i32** %4
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %28)
br label %30
30: ; preds = %24
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %20
33: ; preds = %20
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = mul i64 4, %35
%37 = trunc i64 %36 to i32
%38 = call i64 @malloc(i32 %37)
%39 = inttoptr i64 %38 to i32*
store i32* %39, i32** %6
%40 = load i32*, i32** %6
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = mul i64 4, %42
%44 = trunc i64 %43 to i32
%45 = call i32 @memset(i32* %40, i32 1, i32 %44)
%46 = load i32*, i32** %4
%47 = load i32, i32* %5
%48 = load i32, i32* %5
%49 = sub nsw i32 %48, 1
%50 = load i32*, i32** %6
%51 = call i32 @partition(i32* %46, i32 %47, i32 0, i32 %49, i32* %50)
%52 = load i32*, i32** %6
%53 = load i32, i32* %5
%54 = call i32 @getSumOfArray(i32* %52, i32 %53)
%55 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %54)
%56 = load i32*, i32** %4
%57 = call i32 @free(i32* %56)
%58 = load i32*, i32** %6
%59 = call i32 @free(i32* %58)
br label %8
60: ; 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 i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = add nsw i32 %6, -1
store i32 %7, i32* %1
%8 = icmp eq i32 %6, 0
br i1 %8, label %44, label %9
9: ; preds = %0, %25
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
%12 = shl i32 %11, 3
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i32*
%15 = load i32, i32* %2
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %9, %17
%18 = phi i64 [ %21, %17 ], [ 0, %9 ]
%19 = getelementptr inbounds i32, i32* %14, i64 %18
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %19)
%21 = add nuw nsw i64 %18, 1
%22 = load i32, i32* %2
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %21, %23
br i1 %24, label %17, label %25
25: ; preds = %17, %9
%26 = phi i32 [ %15, %9 ], [ %22, %17 ]
%27 = shl i32 %26, 2
%28 = call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to i32*
%30 = load i32, i32* %2
%31 = shl i32 %30, 2
%32 = call i32 @memset(i32* %29, i32 1, i32 %31)
%33 = load i32, i32* %2
%34 = add nsw i32 %33, -1
%35 = call i32 @partition(i32* %14, i32 %33, i32 0, i32 %34, i32* %29)
%36 = load i32, i32* %2
%37 = call i32 @getSumOfArray(i32* %29, i32 %36)
%38 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = call i32 @free(i32* %14)
%40 = call i32 @free(i32* %29)
%41 = load i32, i32* %1
%42 = add nsw i32 %41, -1
store i32 %42, i32* %1
%43 = icmp eq i32 %41, 0
br i1 %43, label %44, label %9
44: ; preds = %25, %0
ret i32 0
}