while True:

    n = int(eval(input()))

    if n == 0:

        break

    for _ in range(n):

        p = list(map(int, input().split()))

        if 100 in p:

            print("A")

        elif (p[0] + p[1]) // 2 >= 90:

            print("A")

        elif sum(p) // 3 >= 80:

            print("A")

        elif sum(p) // 3 >= 70:

            print("B")

        elif sum(p) // 3 >= 50 and (p[0] >= 80 or p[1] >= 80):

            print("B")

        else:

            print("C")
while True:

    n = int(eval(input()))

    if n == 0:

        break

    for _ in range(n):

        p = list(map(int, input().split()))

        x = sum(p) // 3

        if 100 in p:

            print("A")

        elif (p[0] + p[1]) // 2 >= 90:

            print("A")

        elif x >= 80:

            print("A")

        elif x >= 70:

            print("B")

        elif x >= 50 and (p[0] >= 80 or p[1] >= 80):

            print("B")

        else:

            print("C")
while True:
    n = int(eval(input()))
    if n == 0:
        break
    for _ in range(n):
        p = list(map(int, input().split()))
        if 100 in p:
            print("A")
        elif (p[0] + p[1]) // 2 >= 90:
            print("A")
        elif sum(p) // 3 >= 80:
            print("A")
        elif sum(p) // 3 >= 70:
            print("B")
        elif sum(p) // 3 >= 50 and (p[0] >= 80 or p[1] >= 80):
            print("B")
        else:
            print("C")

while True:
    n = int(eval(input()))
    if n == 0:
        break
    for _ in range(n):
        p = list(map(int, input().split()))
        x = sum(p) // 3
        if 100 in p:
            print("A")
        elif (p[0] + p[1]) // 2 >= 90:
            print("A")
        elif x >= 80:
            print("A")
        elif x >= 70:
            print("B")
        elif x >= 50 and (p[0] >= 80 or p[1] >= 80):
            print("B")
        else:
            print("C")

+        x = sum(p) // 3 -        elif sum(p) // 3 >= 80: +        elif x >= 80: -        elif sum(p) // 3 >= 70: +        elif x >= 70: -        elif sum(p) // 3 >= 50 and (p[0] >= 80 or p[1] >= 80): +        elif x >= 50 and (p[0] >= 80 or p[1] >= 80):