Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 186 ms):
t = int(input())
ans = []
for i in range(t):
    n = input()
    a = n.count("2")
    b = n.count("3")
    v = 0
    for j in n:
        v += int(j)
    r = v%9
    if (a>=2 and b>=2) or (a>=5 and b>=1) or a>=8:
        ans.append("YES")
    elif r==0:
        ans.append("YES")
    elif r==4 and (a>=7 or (a>=4 and b>=1) or (a>=1 and b>=2)):
        ans.append("YES")
    elif r==6 and (a>=6 or (a>=3 and b>=1) or b>=2):
        ans.append("YES")
    elif r==8 and (a>=5 or (a>=2 and b>=1)):
        ans.append("YES")         
    elif r==1 and (a>=4 or (a>=1 and b>=1)):
        ans.append("YES")
    elif r==3 and (a>=3 or b>=1):
        ans.append("YES")
    elif r==5 and a>=2:
        ans.append("YES")
    elif r==7 and a>=1:
        ans.append("YES")
    else:
        ans.append("NO")

for j in ans:
    print(j)

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