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):
#!/usr/bin/python3

# cat test.txt | python3 main.py
import sys
import math


def solve():
    input_data = sys.stdin.read().strip().split()
    idx = 0
    t = int(input_data[idx])
    idx += 1

    results = []
    for _ in range(t):
        n = input_data[idx]
        idx += 1
        res = "NO"
        # process each test case:

        cnt_2 = 0
        cnt_6 = 0

        n_str = str(n)
        n = 0
        for i in range(len(n_str)):
            n += int(n_str[i])
            if n_str[i] == "2":
                cnt_2 += 1
            elif n_str[i] == "3":
                cnt_6 += 1

        if n % 9 == 0:
            res = "YES"
        else:
            twos = [2, 4, 6, 8, 1, 3, 5, 7]
            sixs = [6, 3]

            cnt_2 = min(cnt_2, len(twos))
            cnt_6 = min(cnt_6, len(sixs))

            if cnt_2 > 0:
                for i in range(cnt_2):
                    if (n + twos[i]) % 9 == 0:
                        res = "YES"

            if cnt_6 > 0:
                for i in range(cnt_6):
                    if (n + sixs[i]) % 9 == 0:
                        res = "YES"

            if cnt_6 > 0 and cnt_2 > 0:
                for i in range(cnt_2):
                    for k in range(cnt_6):
                        if (n + sixs[k] + twos[i]) % 9 == 0:
                            res = "YES"

        # store result
        results.append(str(res))

    print("\n".join(results))


if __name__ == "__main__":
    solve()