Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 249 ms):
for i in range(int(input())):
    n=(input())
    a=0
    for i in n:
        a+=int(i)
    a=a%9
    a=9-a
    if a==9:
        print("YES")
    else:
        if a%2!=0:
            p=0
            q=0
            for i in n:
                if i=="2":
                    p+=1
                if i=="3":
                    q+=1
            if a==1:
                if p>=5 or (p>=2 and q>=1):
                    print("YES")
                else:
                    print("NO")
            elif a==3:
                if q>=2 or p>=6 or (q>=1 and p>=3):
                    print("YES")
                else:
                    print("NO")
            elif a==5:
                if p>=7 or (q>=1 and p>=4) or (q>=2 and p>=1):
                    print("YES")
                else:
                    print('NO')
            else:
                if p>=8 or (q>=1 and p>=5) or (q>=2 and p>=2):
                    print("YES")
                else:
                    print("NO")
        else:
            if a<6:
                a=a//2
                ans=0
                for i in n:
                    if i=="2":
                        ans+=1
                if ans>=a:
                    print("YES")
                else:
                    print("NO")
            else:
                if a==6:
                    a=a//2
                    ans=0
                    for i in n:
                        if i=="2":
                            ans+=1
                    if ans>=a:
                        print("YES")
                    else:
                        for i in n:
                            if i=="3":
                                print("YES")
                                break
                        else:
                            print("NO")
                else:
                    a=a//2
                    ans=0
                    for i in n:
                        if i=="2":
                            ans+=1
                    if ans>=a:
                        print("YES")
                    else:
                        if ans<1:
                            print("NO")
                        else:
                            for i in n:
                                if i=="3":
                                    print("YES")
                                    break
                            else:
                                print("NO")

Solution 2 (runtime: 233 ms):
for _ in range(int(input())):
    s = input()
    reachable2 = [0]
    reachable3 = [0]
    div = 0; sky2 = sky3 = 0
    finn = False 
    for i in s:
        div += int(i)
        if sky2 < 10:
            if i == '2':
                reachable2.append(reachable2[-1]+2)
                sky2 += 1
        if sky3 < 5:
            if i == '3':
                reachable3.append(reachable3[-1]+6)
                sky3 += 1 
    need = 9 - div%9
    if need == 9 or need == 0:
        print('yes')
    elif (need == 2 and len(reachable2) > 1) or (need == 4 and len(reachable2) > 2) or (need == 6 and (len(reachable2) > 3 or len(reachable3) > 1)) or (need == 8 and len(reachable2) > 4):
        print('yes')
    else:
        reachable = {(i+j)%9 for i in reachable2 for j in reachable3}
        #print(reachable, reachable2, reachable3)
        #print(div,need, two, three)
        #print(reachable)
        if need in reachable:
            print('yes')
        else:
            print('no')