int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    float sum = 0, x1 = 0;
    int a, c = 0;
    float x = 0;
    scanf("%d", &a);
    float n[a];
    int i, xx;
    for (i = 0; i < a; i++) {
      c++;
      scanf("%f", &n[i]);
      if (i > 0)
        if (n[i - 1] == n[i]) {
          c++;
          if (c == a)
            printf("0\n");
          return 0;
        }
      sum += n[i];
    }
    x = (float)(sum / 6);
    xx = (int)(x)*6;
    if (xx == sum)
      printf("%.0f\n", x - 1);
    else
      printf("ANGRY\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xed2(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     1307 <main+0x1e7>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe90(%rip),%rdi
xor    %eax,%eax
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1273 <main+0x153>
mov    -0x48(%rbp),%rsi
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movslq -0x34(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x0,-0x34(%rbp)
jle    124e <main+0x12e>
mov    -0x48(%rbp),%rax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
movslq -0x34(%rbp),%rcx
ucomiss (%rax,%rcx,4),%xmm0
jne    1249 <main+0x129>
jp     1249 <main+0x129>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1236 <main+0x116>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    12e6 <main+0x1c6>
jmp    124e <main+0x12e>
mov    -0x48(%rbp),%rax
movslq -0x34(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11b1 <main+0x91>
movss  -0xc(%rbp),%xmm0
movss  0xd80(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
cvttss2si -0x1c(%rbp),%eax
imul   $0x6,%eax,%eax
mov    %eax,-0x38(%rbp)
cvtsi2ssl -0x38(%rbp),%xmm0
ucomiss -0xc(%rbp),%xmm0
jne    12d1 <main+0x1b1>
jp     12d1 <main+0x1b1>
movss  -0x1c(%rbp),%xmm0
movss  0xd4e(%rip),%xmm1
subss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd4c(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12df <main+0x1bf>
lea    0xd3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x3c(%rbp),%eax
test   %eax,%eax
je     1302 <main+0x1e2>
jmp    12fd <main+0x1dd>
jmp    130e <main+0x1ee>
jmp    1141 <main+0x21>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%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    0xec0(%rip),%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
subl   $0x1,-0x30(%rbp)
jb     1294 <main+0x164>
lea    0xea7(%rip),%rbx
lea    0xe9d(%rip),%rdi
lea    -0x2c(%rbp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %rsp,%r13
mov    -0x2c(%rbp),%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
cmpl   $0x0,-0x2c(%rbp)
jle    1210 <main+0xe0>
xorps  %xmm2,%xmm2
xor    %r15d,%r15d
xor    %r14d,%r14d
jmp    11d0 <main+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movss  (%r12,%r14,4),%xmm0
movss  -0x34(%rbp),%xmm2
addss  %xmm0,%xmm2
add    $0x1,%r14
movslq -0x2c(%rbp),%rax
add    $0x4,%r15
cmp    %rax,%r14
jge    1213 <main+0xe3>
movss  %xmm2,-0x34(%rbp)
lea    (%r12,%r15,1),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
test   %r14,%r14
je     11b0 <main+0x80>
lea    -0x1(%r14),%eax
movss  (%r12,%rax,4),%xmm1
movss  (%r12,%r14,4),%xmm0
ucomiss %xmm0,%xmm1
jne    11b6 <main+0x86>
jp     11b6 <main+0x86>
jmp    127b <main+0x14b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xorps  %xmm2,%xmm2
movaps %xmm2,%xmm0
divss  0xde2(%rip),%xmm0
cvttss2si %xmm0,%eax
add    %eax,%eax
lea    (%rax,%rax,2),%eax
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
ucomiss %xmm1,%xmm2
jne    1260 <main+0x130>
jp     1260 <main+0x130>
addss  0xdc7(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdc6(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    126c <main+0x13c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xdad(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rsp
subl   $0x1,-0x30(%rbp)
jae    1164 <main+0x34>
jmp    1294 <main+0x164>
sub    -0x2c(%rbp),%r14d
cmp    $0xfffffffe,%r14d
jne    1291 <main+0x161>
lea    0xd8e(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%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 = [3 x i8] c"%f\00"
@.str.2 = [3 x i8] c"0\0A\00"
@.str.3 = [6 x i8] c"%.0f\0A\00"
@.str.4 = [7 x i8] c"ANGRY\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca float
%5 = alloca i32
%6 = alloca i32
%7 = alloca float
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %1
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %14
14: ; preds = %89, %0
%15 = load i32, i32* %2
%16 = add nsw i32 %15, -1
store i32 %16, i32* %2
%17 = icmp ne i32 %15, 0
br i1 %17, label %18, label %90
18: ; preds = %14
store float 0.000000e+00, float* %3
store float 0.000000e+00, float* %4
store i32 0, i32* %6
store float 0.000000e+00, float* %7
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%20 = load i32, i32* %5
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %8
%23 = alloca float, i64 %21
store i64 %21, i64* %9
store i32 0, i32* %10
br label %24
24: ; preds = %65, %18
%25 = load i32, i32* %10
%26 = load i32, i32* %5
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %68
28: ; preds = %24
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
%31 = load i32, i32* %10
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds float, float* %23, i64 %32
%34 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %33)
%35 = load i32, i32* %10
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %58
37: ; preds = %28
%38 = load i32, i32* %10
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds float, float* %23, i64 %40
%42 = load float, float* %41
%43 = load i32, i32* %10
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds float, float* %23, i64 %44
%46 = load float, float* %45
%47 = fcmp oeq float %42, %46
br i1 %47, label %48, label %57
48: ; preds = %37
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
store i32 %50, i32* %6
%51 = load i32, i32* %6
%52 = load i32, i32* %5
%53 = icmp eq i32 %51, %52
br i1 %53, label %54, label %56
54: ; preds = %48
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %56
56: ; preds = %54, %48
store i32 0, i32* %1
store i32 1, i32* %12
br label %86
57: ; preds = %37
br label %58
58: ; preds = %57, %28
%59 = load i32, i32* %10
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds float, float* %23, i64 %60
%62 = load float, float* %61
%63 = load float, float* %3
%64 = fadd float %63, %62
store float %64, float* %3
br label %65
65: ; preds = %58
%66 = load i32, i32* %10
%67 = add nsw i32 %66, 1
store i32 %67, i32* %10
br label %24
68: ; preds = %24
%69 = load float, float* %3
%70 = fdiv float %69, 6.000000e+00
store float %70, float* %7
%71 = load float, float* %7
%72 = fptosi float %71 to i32
%73 = mul nsw i32 %72, 6
store i32 %73, i32* %11
%74 = load i32, i32* %11
%75 = sitofp i32 %74 to float
%76 = load float, float* %3
%77 = fcmp oeq float %75, %76
br i1 %77, label %78, label %83
78: ; preds = %68
%79 = load float, float* %7
%80 = fsub float %79, 1.000000e+00
%81 = fpext float %80 to double
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %81)
br label %85
83: ; preds = %68
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %85
85: ; preds = %83, %78
store i32 0, i32* %12
br label %86
86: ; preds = %85, %56
%87 = load i8*, i8** %8
%88 = load i32, i32* %12
switch i32 %88, label %93 [
i32 0, label %89
i32 1, label %91
]
89: ; preds = %86
br label %14
90: ; preds = %14
store i32 0, i32* %1
br label %91
91: ; preds = %90, %86
%92 = load i32, i32* %1
ret i32 %92
93: ; preds = %86
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%f\00"
@.str.3 = [6 x i8] c"%.0f\0A\00"
@str = [6 x i8] c"ANGRY\00"
@str.5 = [2 x i8] c"0\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 %65, label %8
8: ; preds = %0
%9 = bitcast i32* %2 to i8*
br label %10
10: ; preds = %8, %61
%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 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
%15 = alloca float, i64 %13
%16 = load i32, i32* %2
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %47
18: ; preds = %10, %41
%19 = phi i64 [ %21, %41 ], [ 0, %10 ]
%20 = phi float [ %43, %41 ], [ 0.000000e+00, %10 ]
%21 = add nuw nsw i64 %19, 1
%22 = getelementptr inbounds float, float* %15, i64 %19
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %22)
%24 = icmp eq i64 %19, 0
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = load float, float* %22
br label %41
27: ; preds = %18
%28 = add nuw i64 %19, 4294967295
%29 = and i64 %28, 4294967295
%30 = getelementptr inbounds float, float* %15, i64 %29
%31 = load float, float* %30
%32 = load float, float* %22
%33 = fcmp oeq float %31, %32
br i1 %33, label %34, label %41
34: ; preds = %27
%35 = trunc i64 %19 to i32
%36 = add nuw nsw i32 %35, 2
%37 = load i32, i32* %2
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %60
39: ; preds = %34
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0))
br label %60
41: ; preds = %25, %27
%42 = phi float [ %26, %25 ], [ %32, %27 ]
%43 = fadd float %20, %42
%44 = load i32, i32* %2
%45 = sext i32 %44 to i64
%46 = icmp slt i64 %21, %45
br i1 %46, label %18, label %47
47: ; preds = %41, %10
%48 = phi float [ 0.000000e+00, %10 ], [ %43, %41 ]
%49 = fdiv float %48, 6.000000e+00
%50 = fptosi float %49 to i32
%51 = mul nsw i32 %50, 6
%52 = sitofp i32 %51 to float
%53 = fcmp oeq float %48, %52
br i1 %53, label %54, label %58
54: ; preds = %47
%55 = fadd float %49, -1.000000e+00
%56 = fpext float %55 to double
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %56)
br label %61
58: ; preds = %47
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %61
60: ; preds = %34, %39
br label %65
61: ; preds = %54, %58
%62 = load i32, i32* %1
%63 = add nsw i32 %62, -1
store i32 %63, i32* %1
%64 = icmp eq i32 %62, 0
br i1 %64, label %65, label %10
65: ; preds = %61, %0, %60
ret i32 0
}