#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, i, dist, ele, max;
  int arr[100001];
  scanf("%d", &t);
  while (t--) {
    for (i = 0; i < 100001; i++)
      arr[i] = 0;
    dist = -1;
    scanf("%d", &N);
    for (i = 0; i < N; i++) {
      scanf("%d", &ele);
      arr[ele]++;
    }
    max = 0;
    for (i = 0; i < 100001; i++) {
      if (max < arr[i])
        max = arr[i];
    }
    printf("%d\n", N - max);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x61aa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     124b <main+0x12b>
movl   $0x0,-0x10(%rbp)
cmpl   $0x186a1,-0x10(%rbp)
jge    1187 <main+0x67>
movslq -0x10(%rbp),%rax
movl   $0x0,-0x61aa0(%rbp,%rax,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115d <main+0x3d>
movl   $0xffffffff,-0x14(%rbp)
lea    0xe6b(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e4 <main+0xc4>
lea    0xe48(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
movslq -0x18(%rbp),%rax
mov    -0x61aa0(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x61aa0(%rbp,%rax,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11a5 <main+0x85>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x186a1,-0x10(%rbp)
jge    1234 <main+0x114>
mov    -0x1c(%rbp),%eax
movslq -0x10(%rbp),%rcx
cmp    -0x61aa0(%rbp,%rcx,4),%eax
jge    1221 <main+0x101>
movslq -0x10(%rbp),%rax
mov    -0x61aa0(%rbp,%rax,4),%eax
mov    %eax,-0x1c(%rbp)
jmp    1226 <main+0x106>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11f2 <main+0xd2>
mov    -0xc(%rbp),%esi
sub    -0x1c(%rbp),%esi
lea    0xdc2(%rip),%rdi
call   1030 <printf@plt>
jmp    1142 <main+0x22>
xor    %eax,%eax
add    $0x61aa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x61a98,%rsp
lea    0xeb8(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
subl   $0x1,0x8(%rsp)
jb     12be <main+0x18e>
lea    0x10(%rsp),%r14
lea    0xe97(%rip),%rbx
lea    0x4(%rsp),%r15
lea    0xc(%rsp),%r12
lea    0xe89(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    $0x61a84,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%esi
test   %esi,%esi
jle    11d0 <main+0xa0>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
movslq 0xc(%rsp),%rax
addl   $0x1,0x10(%rsp,%rax,4)
add    $0x1,%ebp
mov    0x4(%rsp),%esi
cmp    %esi,%ebp
jl     11b0 <main+0x80>
pxor   %xmm0,%xmm0
mov    $0xc,%eax
pxor   %xmm1,%xmm1
nopl   (%rax)
movdqa -0x20(%rsp,%rax,4),%xmm2
movdqa -0x10(%rsp,%rax,4),%xmm3
movdqa (%rsp,%rax,4),%xmm4
movdqa 0x10(%rsp,%rax,4),%xmm5
movdqa %xmm0,%xmm6
pcmpgtd %xmm2,%xmm6
pand   %xmm6,%xmm0
pandn  %xmm2,%xmm6
por    %xmm0,%xmm6
movdqa %xmm1,%xmm2
pcmpgtd %xmm3,%xmm2
pand   %xmm2,%xmm1
pandn  %xmm3,%xmm2
por    %xmm1,%xmm2
movdqa %xmm6,%xmm0
pcmpgtd %xmm4,%xmm0
pand   %xmm0,%xmm6
pandn  %xmm4,%xmm0
por    %xmm6,%xmm0
movdqa %xmm2,%xmm1
pcmpgtd %xmm5,%xmm1
pand   %xmm1,%xmm2
pandn  %xmm5,%xmm1
por    %xmm2,%xmm1
add    $0x10,%rax
cmp    $0x186ac,%rax
jne    11e0 <main+0xb0>
movdqa %xmm0,%xmm2
pcmpgtd %xmm1,%xmm2
pand   %xmm2,%xmm0
pandn  %xmm1,%xmm2
por    %xmm0,%xmm2
pshufd $0xee,%xmm2,%xmm0
movdqa %xmm2,%xmm1
pcmpgtd %xmm0,%xmm1
pand   %xmm1,%xmm2
pandn  %xmm0,%xmm1
por    %xmm2,%xmm1
pshufd $0x55,%xmm1,%xmm0
movdqa %xmm1,%xmm2
pcmpgtd %xmm0,%xmm2
pand   %xmm2,%xmm1
pandn  %xmm0,%xmm2
por    %xmm1,%xmm2
movd   %xmm2,%eax
mov    0x61a90(%rsp),%ecx
cmp    %ecx,%eax
cmovl  %ecx,%eax
sub    %eax,%esi
mov    %r13,%rdi
call   1030 <printf@plt>
subl   $0x1,0x8(%rsp)
jae    1180 <main+0x50>
xor    %eax,%eax
add    $0x61a98,%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 = [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
%7 = alloca i32
%8 = alloca [100001 x i32]
store i32 0, i32* %1
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %10
10: ; preds = %61, %0
%11 = load i32, i32* %2
%12 = add nsw i32 %11, -1
store i32 %12, i32* %2
%13 = icmp ne i32 %11, 0
br i1 %13, label %14, label %66
14: ; preds = %10
store i32 0, i32* %4
br label %15
15: ; preds = %22, %14
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 100001
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [100001 x i32], [100001 x i32]* %8, i64 0, i64 %20
store i32 0, i32* %21
br label %22
22: ; preds = %18
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %15
25: ; preds = %15
store i32 -1, i32* %5
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
store i32 0, i32* %4
br label %27
27: ; preds = %38, %25
%28 = load i32, i32* %4
%29 = load i32, i32* %3
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %41
31: ; preds = %27
%32 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [100001 x i32], [100001 x i32]* %8, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = add nsw i32 %36, 1
store i32 %37, i32* %35
br label %38
38: ; preds = %31
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
br label %27
41: ; preds = %27
store i32 0, i32* %7
store i32 0, i32* %4
br label %42
42: ; preds = %58, %41
%43 = load i32, i32* %4
%44 = icmp slt i32 %43, 100001
br i1 %44, label %45, label %61
45: ; preds = %42
%46 = load i32, i32* %7
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [100001 x i32], [100001 x i32]* %8, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = icmp slt i32 %46, %50
br i1 %51, label %52, label %57
52: ; preds = %45
%53 = load i32, i32* %4
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [100001 x i32], [100001 x i32]* %8, i64 0, i64 %54
%56 = load i32, i32* %55
store i32 %56, i32* %7
br label %57
57: ; preds = %52, %45
br label %58
58: ; preds = %57
%59 = load i32, i32* %4
%60 = add nsw i32 %59, 1
store i32 %60, i32* %4
br label %42
61: ; preds = %42
%62 = load i32, i32* %3
%63 = load i32, i32* %7
%64 = sub nsw i32 %62, %63
%65 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %64)
br label %10
66: ; preds = %10
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 = alloca i32
%4 = alloca [100001 x i32]
%5 = bitcast [100001 x i32]* %4 to i8*
%6 = bitcast i32* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = call 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 %71, label %13
13: ; preds = %0
%14 = getelementptr inbounds [100001 x i32], [100001 x i32]* %4, i64 0, i64 100000
br label %15
15: ; preds = %13, %48
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%17 = load i32, i32* %2
%18 = icmp sgt i32 %17, 0
br i1 %18, label %60, label %19
19: ; preds = %60, %15
%20 = phi i32 [ %17, %15 ], [ %69, %60 ]
br label %21
21: ; preds = %21, %19
%22 = phi i64 [ 0, %19 ], [ %46, %21 ]
%23 = phi <4 x i32> [ zeroinitializer, %19 ], [ %44, %21 ]
%24 = phi <4 x i32> [ zeroinitializer, %19 ], [ %45, %21 ]
%25 = getelementptr inbounds [100001 x i32], [100001 x i32]* %4, i64 0, i64 %22
%26 = bitcast i32* %25 to <4 x i32>*
%27 = load <4 x i32>, <4 x i32>* %26
%28 = getelementptr inbounds i32, i32* %25, i64 4
%29 = bitcast i32* %28 to <4 x i32>*
%30 = load <4 x i32>, <4 x i32>* %29
%31 = icmp slt <4 x i32> %23, %27
%32 = icmp slt <4 x i32> %24, %30
%33 = select <4 x i1> %31, <4 x i32> %27, <4 x i32> %23
%34 = select <4 x i1> %32, <4 x i32> %30, <4 x i32> %24
%35 = or i64 %22, 8
%36 = getelementptr inbounds [100001 x i32], [100001 x i32]* %4, i64 0, i64 %35
%37 = bitcast i32* %36 to <4 x i32>*
%38 = load <4 x i32>, <4 x i32>* %37
%39 = getelementptr inbounds i32, i32* %36, i64 4
%40 = bitcast i32* %39 to <4 x i32>*
%41 = load <4 x i32>, <4 x i32>* %40
%42 = icmp slt <4 x i32> %33, %38
%43 = icmp slt <4 x i32> %34, %41
%44 = select <4 x i1> %42, <4 x i32> %38, <4 x i32> %33
%45 = select <4 x i1> %43, <4 x i32> %41, <4 x i32> %34
%46 = add nuw nsw i64 %22, 16
%47 = icmp eq i64 %46, 100000
br i1 %47, label %48, label %21
48: ; preds = %21
%49 = icmp sgt <4 x i32> %44, %45
%50 = select <4 x i1> %49, <4 x i32> %44, <4 x i32> %45
%51 = call i32 @llvm.vector.reduce.smax.v4i32(<4 x i32> %50)
%52 = load i32, i32* %14
%53 = icmp slt i32 %51, %52
%54 = select i1 %53, i32 %52, i32 %51
%55 = sub nsw i32 %20, %54
%56 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %55)
%57 = load i32, i32* %1
%58 = add nsw i32 %57, -1
store i32 %58, i32* %1
%59 = icmp eq i32 %57, 0
br i1 %59, label %71, label %15
60: ; preds = %15, %60
%61 = phi i32 [ %68, %60 ], [ 0, %15 ]
%62 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%63 = load i32, i32* %3
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [100001 x i32], [100001 x i32]* %4, i64 0, i64 %64
%66 = load i32, i32* %65
%67 = add nsw i32 %66, 1
store i32 %67, i32* %65
%68 = add nuw nsw i32 %61, 1
%69 = load i32, i32* %2
%70 = icmp slt i32 %68, %69
br i1 %70, label %60, label %19
71: ; preds = %48, %0
ret i32 0
}