Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 124 ms):
#                             * بسم الله الرحمن الرحيم *
#     ﴾ رَبِّ اشْرَحْ لِي صَدْرِي * وَيَسِّرْ لِي أَمْرِي * وَاحْلُلْ عُقْدَةً مِّن لِّسَانِي * يَفْقَهُوا قَوْلِي ﴿
#  
t=int(input())
for i in range(t):
    n=input()
    intn=int(n)
    result="NO"
    count_2 = n.count('2') 
    count_3 = n.count('3')
    if intn%9==0:
        result="YES"
    else:
        rest=intn%9
        if rest in [1,3,5,7]:
            if rest==7:
                if count_2>=1:
                    result="YES"
            elif rest==5:
                if count_2>=2:
                    result="YES"
            elif rest==3:
                if count_2>=3 or count_3>=1:
                    result="YES"
            elif rest==1:
                if (count_2>=1 and count_3>=1) or count_2>=4:
                    result="YES"
        elif rest in [2,4,6,8]:
            if rest==8:
                if (count_2>=2 and count_3>=1) or count_2>=5:
                    result="YES"
            elif rest==6:
                if (count_3>=2) or (count_2>=3 and count_3>=1) or count_2>=6:
                    result="YES"
            elif rest==4:
                if (count_2>=4 and count_3>=1) or (count_2>=1 and count_3>=2) or count_2>=7:
                    result="YES"
            elif rest==2:
                if (count_2>=5 and count_3>=1) or (count_2>=2 and count_3>=2) or count_2>=8:
                    result="YES"
                
    print(result)

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")