#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 /*<<< orphan*/ scanf(char *, int *, ...);
int main(void) {
  int num, pm, pe, pj, i, ave;
  while (1) {
    scanf("%d", &num);
    if (num == 0)
      break;
    for (i = 0; i < num; i++) {
      scanf("%d %d %d", &pm, &pe, &pj);
      ave = (pm + pe + pj) / 3;
      if (pm == 100 || pe == 100 || pj == 100 || (pm + pe) / 2 >= 90 ||
          ave >= 80) {
        printf("A\n");
      } else if (ave >= 70 || (ave >= 50 && (pm >= 80 || pe >= 80))) {
        printf("B\n");
      } else {
        printf("C\n");
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xed0(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1150 <main+0x30>
jmp    1243 <main+0x123>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    123e <main+0x11e>
lea    0xe96(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
cmpl   $0x64,-0xc(%rbp)
je     11d0 <main+0xb0>
cmpl   $0x64,-0x10(%rbp)
je     11d0 <main+0xb0>
cmpl   $0x64,-0x14(%rbp)
je     11d0 <main+0xb0>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x5a,%eax
jge    11d0 <main+0xb0>
cmpl   $0x50,-0x1c(%rbp)
jl     11e1 <main+0xc1>
lea    0xe32(%rip),%rdi
call   1030 <printf@plt>
jmp    122b <main+0x10b>
cmpl   $0x46,-0x1c(%rbp)
jge    1209 <main+0xe9>
cmpl   $0x32,-0x1c(%rbp)
jl     121a <main+0xfa>
cmpl   $0x50,-0xc(%rbp)
jge    1209 <main+0xe9>
cmpl   $0x50,-0x10(%rbp)
jl     121a <main+0xfa>
lea    0xdfc(%rip),%rdi
call   1030 <printf@plt>
jmp    1226 <main+0x106>
lea    0xdee(%rip),%rdi
call   1030 <printf@plt>
jmp    122b <main+0x10b>
jmp    1230 <main+0x110>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1157 <main+0x37>
jmp    112f <main+0xf>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xed1(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x8(%rsp),%eax
test   %eax,%eax
je     1240 <main+0x120>
lea    0xeac(%rip),%r14
lea    0x14(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%rbx
lea    0xea3(%rip),%r13
jmp    118f <main+0x6f>
nopl   0x0(%rax)
lea    0xe8f(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x8(%rsp),%eax
test   %eax,%eax
je     1240 <main+0x120>
test   %eax,%eax
jle    1170 <main+0x50>
xor    %ebp,%ebp
jmp    11ae <main+0x8e>
lea    0xe6b(%rip),%rdi
xchg   %ax,%ax
call   1030 <puts@plt>
add    $0x1,%ebp
cmp    0x8(%rsp),%ebp
jge    1170 <main+0x50>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x14(%rsp),%eax
mov    %r13,%rdi
cmp    $0x64,%eax
je     11a0 <main+0x80>
mov    0x10(%rsp),%ecx
mov    %r13,%rdi
cmp    $0x64,%ecx
je     11a0 <main+0x80>
mov    0xc(%rsp),%esi
mov    %r13,%rdi
cmp    $0x64,%esi
je     11a0 <main+0x80>
lea    (%rcx,%rax,1),%edx
mov    %r13,%rdi
cmp    $0xb3,%edx
jg     11a0 <main+0x80>
add    %esi,%edx
mov    %r13,%rdi
cmp    $0xef,%edx
jg     11a0 <main+0x80>
lea    0xe04(%rip),%rdi
cmp    $0xd1,%edx
jg     11a0 <main+0x80>
cmp    $0x96,%edx
jl     1197 <main+0x77>
lea    0xde9(%rip),%rdi
cmp    $0x4f,%eax
jg     11a0 <main+0x80>
lea    0xdd9(%rip),%rdi
cmp    $0x4f,%ecx
jle    1197 <main+0x77>
jmp    11a0 <main+0x80>
xor    %eax,%eax
add    $0x18,%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 = [9 x i8] c"%d %d %d\00"
@.str.2 = [3 x i8] c"A\0A\00"
@.str.3 = [3 x i8] c"B\0A\00"
@.str.4 = [3 x i8] c"C\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
store i32 0, i32* %1
br label %8
8: ; preds = %0, %66
%9 = call i32 (i8*, 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 %12, label %13
12: ; preds = %8
br label %67
13: ; preds = %8
store i32 0, i32* %6
br label %14
14: ; preds = %63, %13
%15 = load i32, i32* %6
%16 = load i32, i32* %2
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %66
18: ; preds = %14
%19 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = add nsw i32 %20, %21
%23 = load i32, i32* %5
%24 = add nsw i32 %22, %23
%25 = sdiv i32 %24, 3
store i32 %25, i32* %7
%26 = load i32, i32* %3
%27 = icmp eq i32 %26, 100
br i1 %27, label %43, label %28
28: ; preds = %18
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 100
br i1 %30, label %43, label %31
31: ; preds = %28
%32 = load i32, i32* %5
%33 = icmp eq i32 %32, 100
br i1 %33, label %43, label %34
34: ; preds = %31
%35 = load i32, i32* %3
%36 = load i32, i32* %4
%37 = add nsw i32 %35, %36
%38 = sdiv i32 %37, 2
%39 = icmp sge i32 %38, 90
br i1 %39, label %43, label %40
40: ; preds = %34
%41 = load i32, i32* %7
%42 = icmp sge i32 %41, 80
br i1 %42, label %43, label %45
43: ; preds = %40, %34, %31, %28, %18
%44 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %62
45: ; preds = %40
%46 = load i32, i32* %7
%47 = icmp sge i32 %46, 70
br i1 %47, label %57, label %48
48: ; preds = %45
%49 = load i32, i32* %7
%50 = icmp sge i32 %49, 50
br i1 %50, label %51, label %59
51: ; preds = %48
%52 = load i32, i32* %3
%53 = icmp sge i32 %52, 80
br i1 %53, label %57, label %54
54: ; preds = %51
%55 = load i32, i32* %4
%56 = icmp sge i32 %55, 80
br i1 %56, label %57, label %59
57: ; preds = %54, %51, %45
%58 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %61
59: ; preds = %54, %48
%60 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %61
61: ; preds = %59, %57
br label %62
62: ; preds = %61, %43
br label %63
63: ; preds = %62
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
store i32 %65, i32* %6
br label %14
66: ; preds = %14
br label %8
67: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c"%d %d %d\00"
@str = [2 x i8] c"C\00"
@str.5 = [2 x i8] c"B\00"
@str.6 = [2 x i8] c"A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
%11 = icmp eq i32 %10, 0
br i1 %11, label %51, label %16
12: ; preds = %45, %16
%13 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%14 = load i32, i32* %1
%15 = icmp eq i32 %14, 0
br i1 %15, label %51, label %16
16: ; preds = %0, %12
%17 = phi i32 [ %14, %12 ], [ %10, %0 ]
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %12
19: ; preds = %16, %45
%20 = phi i32 [ %48, %45 ], [ 0, %16 ]
%21 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
%22 = load i32, i32* %2
%23 = load i32, i32* %3
%24 = add nsw i32 %23, %22
%25 = load i32, i32* %4
%26 = add nsw i32 %24, %25
%27 = icmp eq i32 %22, 100
%28 = icmp eq i32 %23, 100
%29 = select i1 %27, i1 true, i1 %28
%30 = icmp eq i32 %25, 100
%31 = select i1 %29, i1 true, i1 %30
br i1 %31, label %45, label %32
32: ; preds = %19
%33 = icmp sgt i32 %24, 179
%34 = icmp sgt i32 %26, 239
%35 = select i1 %33, i1 true, i1 %34
br i1 %35, label %45, label %36
36: ; preds = %32
%37 = icmp sgt i32 %26, 209
br i1 %37, label %45, label %38
38: ; preds = %36
%39 = icmp sgt i32 %26, 149
br i1 %39, label %40, label %44
40: ; preds = %38
%41 = icmp sgt i32 %22, 79
%42 = icmp sgt i32 %23, 79
%43 = select i1 %41, i1 true, i1 %42
br i1 %43, label %45, label %44
44: ; preds = %40, %38
br label %45
45: ; preds = %36, %40, %19, %32, %44
%46 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0), %44 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.6, i64 0, i64 0), %32 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.6, i64 0, i64 0), %19 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0), %40 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0), %36 ]
%47 = call i32 @puts(i8* dereferenceable(1) %46)
%48 = add nuw nsw i32 %20, 1
%49 = load i32, i32* %1
%50 = icmp slt i32 %48, %49
br i1 %50, label %19, label %12
51: ; preds = %12, %0
ret i32 0
}