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: 124 ms):
def can_be_divisible_by_9(n_str):
    # 计算数字各位之和
    S = sum(int(ch) for ch in n_str)
    if S % 9 == 0:
        return "YES"
    
    # 计算目标值
    target = (-S) % 9
    new_target = (5 * target) % 9
    
    # 统计数字中2和3的个数
    cnt2 = n_str.count('2')
    cnt3 = n_str.count('3')
    
    # 枚举选择多少个3的平方（6）
    for b in range(0, min(cnt3, 8) + 1):
        a = (new_target - 3 * b) % 9
        if 0 <= a <= cnt2:
            return "YES"
    return "NO"

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    
    idx = 0
    t = int(data[idx])
    idx += 1
    results = []
    
    for _ in range(t):
        n_str = data[idx]
        idx += 1
        result = can_be_divisible_by_9(n_str)
        results.append(result)
    
    for res in results:
        print(res)

if __name__ == "__main__":
    main()