#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 */
typedef int /*<<< orphan*/ arr;

/* Variables and functions */
int printArray(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ sortByFrequency(int *, int);
int main() {
  int t, n1, n2, p;
  scanf("%d", &p);
  while (p--) {
    scanf("%d", &n1);
    int arr[n1];
    for (t = 0; t < n1; t++)
      scanf("%d", &arr[t]);
    int n = sizeof(arr) / sizeof(arr[0]);
    sortByFrequency(arr, n);
    n2 = printArray(arr, n);
    if (n2 > (n1 / 2))
      printf("%d\n", arr[0]);
    else
      printf("NO MAJOR\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     1265 <main+0x125>
lea    0xe86(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ea <main+0xaa>
mov    -0x38(%rbp),%rsi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe29(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b5 <main+0x75>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
shl    $0x2,%rax
shr    $0x2,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
call   1040 <sortByFrequency@plt>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1060 <printArray@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
cmp    %ecx,%eax
jle    124b <main+0x10b>
mov    -0x38(%rbp),%rax
mov    (%rax),%esi
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1259 <main+0x119>
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
jmp    115f <main+0x1f>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe98(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <scanf@plt>
subl   $0x1,-0x30(%rbp)
jae    1188 <main+0x38>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe71(%rip),%r13
jmp    11b9 <main+0x69>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
subl   $0x1,-0x30(%rbp)
jb     1177 <main+0x27>
mov    %r13,%rdi
lea    -0x2c(%rbp),%rsi
call   1060 <scanf@plt>
mov    %rsp,-0x38(%rbp)
mov    -0x2c(%rbp),%r15d
mov    %rsp,%r12
lea    0xf(,%r15,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
cmpl   $0x0,-0x2c(%rbp)
jle    120c <main+0xbc>
mov    %r12,%rbx
xor    %r14d,%r14d
xchg   %ax,%ax
mov    %r13,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
add    $0x1,%r14
movslq -0x2c(%rbp),%rax
add    $0x4,%rbx
cmp    %rax,%r14
jl     11f0 <main+0xa0>
mov    %r12,%rdi
mov    %r15d,%esi
call   1050 <sortByFrequency@plt>
mov    %r12,%rdi
mov    %r15d,%esi
call   1070 <printArray@plt>
mov    -0x2c(%rbp),%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
cmp    %edx,%eax
jle    11a0 <main+0x50>
mov    (%r12),%esi
lea    0xdc2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11ac <main+0x5c>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [10 x i8] c"NO MAJOR\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca 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* %5)
br label %10
10: ; preds = %50, %0
%11 = load i32, i32* %5
%12 = add nsw i32 %11, -1
store i32 %12, i32* %5
%13 = icmp ne i32 %11, 0
br i1 %13, label %14, label %52
14: ; preds = %10
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%16 = load i32, i32* %3
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %6
%19 = alloca i32, i64 %17
store i64 %17, i64* %7
store i32 0, i32* %2
br label %20
20: ; preds = %29, %14
%21 = load i32, i32* %2
%22 = load i32, i32* %3
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %19, i64 %26
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %27)
br label %29
29: ; preds = %24
%30 = load i32, i32* %2
%31 = add nsw i32 %30, 1
store i32 %31, i32* %2
br label %20
32: ; preds = %20
%33 = mul nuw i64 4, %17
%34 = udiv i64 %33, 4
%35 = trunc i64 %34 to i32
store i32 %35, i32* %8
%36 = load i32, i32* %8
%37 = call i32 @sortByFrequency(i32* %19, i32 %36)
%38 = load i32, i32* %8
%39 = call i32 @printArray(i32* %19, i32 %38)
store i32 %39, i32* %4
%40 = load i32, i32* %4
%41 = load i32, i32* %3
%42 = sdiv i32 %41, 2
%43 = icmp sgt i32 %40, %42
br i1 %43, label %44, label %48
44: ; preds = %32
%45 = getelementptr inbounds i32, i32* %19, i64 0
%46 = load i32, i32* %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %46)
br label %50
48: ; preds = %32
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %50
50: ; preds = %48, %44
%51 = load i8*, i8** %6
br label %10
52: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@str = [9 x i8] c"NO MAJOR\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* %2)
%6 = load i32, i32* %2
%7 = add nsw i32 %6, -1
store i32 %7, i32* %2
%8 = icmp eq i32 %6, 0
br i1 %8, label %40, label %9
9: ; preds = %0, %36
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%11 = load i32, i32* %1
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
%14 = alloca i32, i64 %12
%15 = load i32, i32* %1
%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* %1
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %21, %23
br i1 %24, label %17, label %25
25: ; preds = %17, %9
%26 = call i32 @sortByFrequency(i32* %14, i32 %11)
%27 = call i32 @printArray(i32* %14, i32 %11)
%28 = load i32, i32* %1
%29 = sdiv i32 %28, 2
%30 = icmp sgt i32 %27, %29
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = load i32, i32* %14
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %32)
br label %36
34: ; preds = %25
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %36
36: ; preds = %34, %31
%37 = load i32, i32* %2
%38 = add nsw i32 %37, -1
store i32 %38, i32* %2
%39 = icmp eq i32 %37, 0
br i1 %39, label %40, label %9
40: ; preds = %36, %0
ret i32 0
}