Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 249 ms):
for t in range(int(input())):
    s = input()
    sm = 0
    for i in s:
        sm += int(i)

    mod = sm%9

    if mod==0:
        print('YES')
    
    else:
        count2 = 0
        count3 = 0
        for char in s:
            if char=='2':
                count2 += 1
            elif char=='3':
                count3 += 1

        if mod==1:
            if count2>=4 or (count2>=1 and count3>=1):
                print('YES')
            else:
                print('NO')

        elif mod==2:
            if (count2>=2 and count3>=2) or (count2>=5 and count3>=1) or (count2>=8):
                print('YES')
            else:
                print("NO")

        elif mod==3:
            if (count3>=1) or (count2>=3):
                print('YES')
            else:
                print("NO")

        elif mod==4:
            if (count2>=4 and count3>=1) or (count2>=1 and count3>=2) or (count2>=7):
                print('YES')
            else:
                print("NO")

        elif mod==5:
            if (count2>=2):
                print('YES')
            else:
                print("NO")

        elif mod==6:
            if (count2>=6) or (count2>=3 and count3>=1) or (count3>=2):
                print('YES')
            else:
                print("NO")

        elif mod==7:
            if (count2>=1):
                print('YES')
            else:
                print("NO")

        elif mod==8:
            if (count2>=5) or (count2>=2 and count3>=1):
                print('YES')
            else:
                print("NO")

Solution 2 (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")