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: 77 ms):
def is_possible(n, k2, k3, d):
    # Case 1: b ≡ 0 mod 3
    e = 0
    a = (d - e + 9) % 9 * 5 % 9
    if a <= k2:
        return True
    # Case 2: b ≡ 1 mod 3, possible only if k3 >= 1
    if k3 >= 1:
        e = 6
        a = (d - e + 9) % 9 * 5 % 9
        if a <= k2:
            return True
    # Case 3: b ≡ 2 mod 3, possible only if k3 >= 2
    if k3 >= 2:
        e = 3
        a = (d - e + 9) % 9 * 5 % 9
        if a <= k2:
            return True
    return False

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    t = int(data[0])
    index = 1
    for _ in range(t):
        n = data[index]
        index += 1
        S = sum(int(ch) for ch in n)
        d = (-S) % 9
        k2 = n.count('2')
        k3 = n.count('3')
        if is_possible(n, k2, k3, d):
            print("YES")
        else:
            print("NO")

if __name__ == "__main__":
    main()