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: 93 ms):
import sys



def is_interesting(n):

    S = 0

    count_2 = 0

    count_3 = 0



    # Compute sum of digits and count of 2s and 3s

    for digit in n:

        d = int(digit)

        S += d

        if d == 2:

            count_2 += 1

        elif d == 3:

            count_3 += 1



    # Compute R = (9 - S % 9) % 9

    R = (9 - (S % 9)) % 9

    for i in range(count_3+1):

        new_R = (R - 6*i)%9

        if new_R<0:

            new_R +=9

        mmi = (new_R*5)%9

        if mmi <= count_2:

            return 'YES'

    return 'NO'



# Fast input handling

input = sys.stdin.read

data = input().split()

t = int(data[0])

results = []



for i in range(1, t + 1):

    n = data[i]

    results.append(is_interesting(n))



# Output results efficiently

sys.stdout.write("\n".join(results) + "\n")