Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 46 ms):
#include<bits/stdc++.h>
using namespace std;

int a[100005],t;
char s[100005];

int check(int sum){
	if(sum%9==0){
		return 1;
	} else {
		return 0;
	}
}

int main()
{
	memset(a,0,sizeof(a));
	scanf("%d",&t);
	while(t--){
		scanf("%s",s);
		int len=strlen(s);
		int sum2=0,sum3=0,sum=0;
		for(int i=0;i<len;i++){
			if(s[i]-'0'==2){
				sum2++;
				sum+=2;
			} else if(s[i]-'0'==3){
				sum3++;
				sum+=3;
			} else {
				sum+=(s[i]-'0');
			}
		}
		int flag=0;
		if(check(sum)==1){
			printf("Yes\n");
		} else {
			for(int i=0;i<=sum2;i++){
				for(int j=0;j<=sum3;j++){
					sum=sum+2*i+6*j;
					if(check(sum)==1){
						printf("Yes\n");
						flag=1;
						goto out;
					}
					sum=sum-2*i-6*j;
				}
			}
			if(flag==0){
				printf("No\n");
			}
		}
		out:
			flag=flag;
	}
}

Solution 2 (runtime: 61 ms):
/*================================================================================================================================
                    ⠘⣷⣶⣤⣄⡀
                    ⠸⣿⣿⣿⣿⣷⡒⢄⡀
                        ⢹⣿⣿⣿⣿⣿⣆⠙⡄ ⠐
        ⣤⣤⣤⣤⣤⣤⣤⣤⣤⠤⢄⡀  ⣿⣿⣿⣿⣿⣿⡆⠘⡄ ⡆
        ⠈⠙⢿⣿⣿⣿⣿⣿⣿⣿⣦⡈⠒⢄⢸⣿⣿⣿⣿⣿⣿⡀⠱ ⡇
            ⠈⠻⣿⣿⣿⣿⣿⣿⣿⣦ ⠱⣿⣿⣿⣿⣿⣿⣇ ⢃⡇
                ⠘⢿⣿⣿⣿⣿⣿⣿⣷⡄⣹⣿⣿⣿⣿⣿⣿⣶⣾⣿⣶⣤⣀
                ⣀⣀⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀
        ⢀⣠⣴⣶⣿⣭⣍⡉⠙⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷
    ⢀⣠⣶⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇   ⣀
    ⠉⠉⠛⠻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡷⢂⣓⣶⣶⣶⣶⣤⣤⣄⣀
            ⠈⠙⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿⣿⠟⢀⣴⢿⣿⣿⣿⠟⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⠋⠉
            ⠤⠤⠤⠤⠙⣻⣿⣿⣿⣿⣿⣿⣾⣿⣿⡏⣠⠟⡉⣾⣿⣿⠋⡠⠊⣿⡟⣹⣿⢿⣿⣿⣿⠿⠛⠉
        ⢀⣠⣤⣶⣤⣭⣤⣼⣿⢛⣿⣿⣿⣿⣻⣿⣿⠇⠐⢀⣿⣿⡷⠋ ⢠⣿⣺⣿⣿⢺⣿⣋⣉⣉⣩⣴⣶⣤⣤⣄
            ⠉⠉⠛⠻⠿⣿⣿⣿⣇⢻⣿⣿⡿⠿⣿⣯⡀ ⢸⣿⠋⢀⣠⣶⠿⠿⢿⡿⠈⣾⣿⣿⣿⣿⡿⠿⠛⠋⠁
                ⠙⠻⢧⡸⣿⣿⣿ ⠃⠻⠟⢦⢾⢣⠶⠿⠏ ⠰ ⣼⡇⣸⣿⣿⠟⠉  ⢀
                ⢀⣠⣴⣾⣶⣽⣿⡟⠓⠒  ⡀ ⠠⠤⠬⠉⠁⣰⣥⣾⣿⣿⣶⣶⣷⡶⠄
                ⠉⠉⠉⠉⠹⠟⣿⣿⡄  ⠠⡇     ⢠⡟⠛⠛⠋⠉
                    ⢀⣠⠋⠹⣷⣄ ⠐⣊⣀  ⢀⡴⠁⠣⣀
                ⢀⣀⣤⣀⠤⠊⢁⡸ ⣆⠹⣿⣧⣀  ⡠⠖⡑⠁   ⠑⢄⣀⣀
            ⣰⣦⣶⣿⣿⣟⣁⣤⣾⠟⠁⢀⣿⣆⠹⡆⠻⣿⠉⢀⠜⡰  ⠈⠑⢦⡀⠈⢾⠑⡾⠲⣄ ⣀
        ⣀⣤⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠖⠒⠚⠛⠛⠢⠽⢄⣘⣤⡎⠠⠿⠂ ⠠⠴⠶⢉⡭⠃⢸⠃ ⣿⣿⣿⠡⣀
    ⡤⠶⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣋⠁     ⢹⡇    ⠒⠢⣤⠔⠁ ⢀⡏  ⢸⣿⣿ ⢻⡟⠑⠢⢄⡀
    ⢸   ⡀⠉⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⣀⣀⡀ ⢸⣷⡀⣀⣀⡠⠔⠊  ⢀⣠⡞   ⢸⣿⡿ ⠘    ⠈⠑⢤
⢀⣴⣿⡀  ⡇   ⠈⣿⣿⣿⣿⣿⣿   L O N Y   C O D E   ⢀⣠⣴⣾⣿⡿⠁   ⢸⡿⠁        ⡜
⢀⣾⣿⣿⡇ ⢰⣷ ⢀  ⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿ CP  <3  ⢀⣀⣤⣶⣾⣿⣿⣿⢿⠿⠁    ⠘         ⡰⠉⢦
⢀⣼⣿⣿⡿⢱ ⢸⣿⡀⢸⣧⡀ ⢿⣿⣿⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡭⠖⠁ ⡠⠂        ⢠   ⢠⠃ ⠈⣀
⢸⣿⣿⣿⡇ ⢧⢸⣿⣇⢸⣿⣷⡀⠈⣿⣿⣇⠈⠛⢿⣿⣿⣿⣿⣿⣿⠿⠿⠿⠿⠿⠿⠟⡻⠟⠉  ⡠⠊ ⢠        ⣾⡄ ⢠⣿⠔⠁ ⢸
⠈⣿⣿⣿⣷⡀ ⢻⣿⣿⡜⣿⣿⣷⡀⠈⢿⣿⡄  ⠈⠛⠿⣿⣿⣿⣷⣶⣶⣶⡶⠖⠉ ⣀⣤⡶⠋ ⣠⣶⡏       ⢰⣿⣧⣶⣿⣿⠖⡠⠖⠁
⣿⣿⣷⣌⡛⠶⣼⣿⣿⣷⣿⣿⣿⣿⡄⠈⢻⣷ ⣄⡀   ⠈⠉⠛⠛⠛⠁⣀⣤⣶⣾⠟⠋ ⣠⣾⣿⡟        ⣿⣿⣿⣿⣿⠷⠊ ⢰
⢰⣿⣿ ⠈⢉⡶⢿⣿⣿⣿⣿⣿⣿⣿⣿⣆ ⠙⢇⠈⢿⣶⣦⣤⣀⣀⣠⣤⣶⣿⣿⡿⠛⠁⢀⣤⣾⣿⣿⡿⠁       ⣸⣿⡿⠿⠋⠙⠒⠄ ⠉⡄
⣿⣿⡏  ⠁   ⠉⠉⠙⢻⣿⣿⣿⣿⣷⡀   ⠻⣿⣿⣿⣿⣿⠿⠿⠛⠁ ⣀⣴⣿⣿⣿⣿⠟        ⢠⠏         ⠰
===============================================================================================================================*/
#include <bits/stdc++.h>
using namespace std;
typedef long long f_society;
const f_society MOD = 1000000007; 
typedef pair<f_society, f_society> ii;
#define iii pair<f_society, ii>
#define f(x, a, b) for (f_society x = a; x <= b; x++)
#define pb push_back
#define pf push_front
#define MP make_pair
#define vf_society vector<f_society>
#define F first
#define S second
#define endl '\n'
#define ll long long
#define _CP_MAKES_SENIORS_ ios::sync_with_stdio(false);
#define LONY_CODE cin.tie(nullptr);
#define all(v) v.begin(),v.end()
#define inpt(n,asd) for(ll i=0;i<n;i++)cin>>asd[i];
#define no "NO"
#define yes "YES"
#define alice "ALICE"
#define bob "BOB"
#define ld long double
#define space " "
#define scan_mp(asd,mp) for(auto & val : asd) {cin >> val;mp[val]++;}
#define scan_st(asd,st) for(auto & val : asd) {cin >> val;st.insert(val);}
#define scan(asd) for(auto & val : asd) {cin >> val;}
#define scan_i(asd,n) for(int i = 0 ; i < n ; i++) {cin >> asd[i];}
#define scan_i_ind(asd,n) for(int i = 0 ; i < n ; i++) {cin >> asd[i].first; asd[i].second = i+1;}
string alpt="$abcdefghijklmnopqrstuvwxyz"; // A->Z : (65-90) || a->z : (97-122)
const double pi=3.14159265358979323846264338327950288419;
int dx[] = {1,-1,0,0,1,1,-1,-1};
int dy[] = {0,0,1,-1,1,-1,1,-1};
char dc[] = {'D','U','R','L'};
//==================================================-Functions Block-===========================================================================================================================================================================================
bool isPrime(int n) { if (n <= 1) { return false; }if (n <= 3) { return true; }if (n % 2 == 0 || n % 3 == 0) { return false; }int sqrtN = sqrt(n); for (int i = 5; i <= sqrtN; i += 6) { if (n % i == 0 || n % (i + 2) == 0)return false; }return true; }
bool isPowerOfTwo(int n) { return false ? n == 0 : floor(log2(n)) == ceil(log2(n)); }
bool isPowerOfTen(int n) { return false ? n == 0 : floor(log2(n) / log2(10)) == ceil(log2(n) / log2(10)); }
int gcd(int a, int b) { if (a == 0) { return b; }return gcd(b % a, a); }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int numberOfDivisors(int n) { int primes[] = { 2,3,5,7,11,13,17,19 }; int num = 1, ans = 1; for (int it : primes) { int c = 0; while (n % it == 0) { n /= it; c++; }ans *= c + 1; num *= it; }int all = 0; for (int i = 1; i < num; i++) { bool can = 1; for (int it : primes) { if (i % it == 0) { can = 0; } }if (can) { int o = i; for (; o * o < n; o += num) { if (n % o == 0) { all += 2; } }if (o * o == n) { all++; } } }return ans * all; } //bb
int powermod(int x, int y, int p) { int res = 1; x = x % p; if (x == 0) { return 0; }while (y > 0) { if (y & 1) { res = (res * x) % p; }y = y >> 1; x = (x * x) % p; }return res; }
int ncr(int n, int r) { int num = 1, den = 1; for (int i = 1; i <= r; i++) { num *= (n - i + 1); den *= i; int g = gcd(num, den); num /= g, den /= g; }return num; }
bool compareParity(long a, long b) { return (a & 1 && b & 1) || (!(a & 1) && !(b & 1)); }
bool Greater(int a, int b) { return a > b; }
bool isFactorial(int n) { if (n == 1) { return true; }for (int i = 2; i < 17; i++) { int fact = 1; for (int j = i; j >= 2; j--) { fact *= j; }if (fact == n) { return true; } }return false; }
string DecimalToBinary(int n) { if (n == 0) { return "0"; }string binary = ""; while (n > 0) { binary += to_string(n % 2); n /= 2; }reverse(binary.begin(), binary.end()); return binary; }
int factorial(int n) { if (n <= 1) { return 1; }return n * factorial(n - 1); }
void generateFact(vector<int>& v) { for (int i = 1; i <= 14; i++) { v.push_back(factorial(i)); } }
int sum_0_to_n(int n) { return (n) * (n + 1) / 2; }
int sum_m_to_n(int m, int n) { return sum_0_to_n(n) - sum_0_to_n(m); }
int mulmod(int a, int b, int m) { int res = 0; while (b > 0) { if (b & 1)  res = ((m - res) > a) ? res + a : res + a - m; b >>= 1; if (b) a = ((m - a) > a) ? a + a : a + a - m; }return res; } //bb
int power(int a, int b, int m) { if (b == 0) return 1; if (b & 1) return mulmod(a, power(a, b - 1, m), m); int tmp = power(a, b / 2, m); return mulmod(tmp, tmp, m); }  //bb
bool prime(int n) { if (n <= 1)return 0; for (int i = 0; i < 10; i++) { int tmp = (rand() % (n - 1)) + 1; if (power(tmp, n - 1, n) != 1)return false; }return true; }  //bb
bool sortByFirst(pair<int, int>a, pair<int, int>b) { return a.first < b.first; }
int maxNoOfConsecutiveFactors(int n) { for (int i = 2; i <= n + 1; i++) { if (n - i * (n / i) != 0) { return i - 1; } }return 1; }
int countOnes(int num) { int count = 0; while (num != 0) { num = num & (num - 1); count++; }return count; }
int noOfDivisors(int n) { int count = 0, sqrtN = sqrt(n); for (int i = 1; i * i <= n; i++) { if (n - i * (n / i) == 0) { count += 2; } }if (n == sqrtN * sqrtN) { count--; }return count; }
int BinaryToDecimal(string binary) { int decimal = 0; int base = 1; for (int i = binary.length() - 1; i >= 0; i--) { if (binary[i] == '1') { decimal += base; }base *= 2; }return decimal; }
int lowbit(int n) { return n & (-n); } // return pow(2,the first occurence of '1' in binary rep of n [0-based])
int mul(int a,int b,int MOD) {return ((a%MOD)*(b%MOD))%MOD;}
long long factmod(int n) {long long result = 1;for(int i = 2; i <= n; i++) {result = mul(result,i,MOD) % MOD;}return result;}
void sieveOfEratosthenes(vector<int>& composite, int sz) { composite[0] = composite[1] = 1; for (int i = 2; i * i < sz; i++) { if (!composite[i]) { for (int j = i * i; j < sz; j += i) { composite[j] = 1; } } } }// nlog(log(n))
int add(int a, int b, int MOD) {if (MOD <= a) a = a % MOD;if (MOD <= b) b = b % MOD;return MOD <= a + b ? (a + b) % MOD : a + b;}
int sub(int a, int b, int MOD) {if (MOD <= a) a = a % MOD;if (MOD <= b) b = b % MOD;return a <= b ? (a - b + MOD) % MOD : a - b;}
int fastpow(int a, int b, int MOD) {if (MOD <= a) a = a % MOD;int ans = 1;while (b) {if (b & 1) {ans = ans * a;if (MOD <= ans) ans = ans % MOD;}a = a * a;if (MOD <= a) a = a % MOD;b = b / 2;}return ans;}
int inv(int a, int MOD) { return fastpow(a, MOD - 2, MOD);}
int div(int a, int b, int MOD) { return mul(a, inv(b, MOD), MOD);}
//=====================================================================================================================================================================================================================================
/*  --------------------LOGIC CODE----------------------------*/
/*   Practicing Makes GrandMaster !! */

void code(void) {
    string s; cin >> s;
    ll sm [] = {0,0};
    ll res(0);
    for(int i = 0 ; i < s.size() ; i++) {
        res+= s[i] - '0';
        if(s[i] == '2') sm[1]++;
        if(s[i] == '3') sm[0]++;
    }
    bool ans = false;
    if(res%9==0) {
        ans = true;
    }
    while(sm[0] or sm[1]) {
        if(res%9==0) {
            ans = true;
            break;
        }
        if(sm[1] and (res + 2)%9==0) {
            ans = true; 
            break;
        }
        if(sm[1] > 1 and (res + 4)%9==0) {
            ans = true;
            break;
        }
        if(sm[0]) {
            res+=6;
            sm[0]--;
        } else if(sm[1] > 2) {
            res+=6;
            sm[1]-=3;
        } else {
            break;
        }
        if(res%9==0) {
            ans = true;
            break;
        }
    }
    
    if(ans) cout << yes << endl;
    else cout << no << endl;
}
/* -----------------END OF LOGIC CODE --------------------*/
    /*  --------------------MAIN PROGRAM----------------------------*/
        // !Cp is nothing but only observation and mathematics.
bool testCases = 1;
signed main(void) {
    _CP_MAKES_SENIORS_   
    LONY_CODE
    /*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    */
    int tc = 1; if(testCases) cin >> tc; 
    while(tc--) code();
    /* -----------------END OF PROGRAM --------------------*/
}
    /*      
    *    Rules To Get an Accepted Solution: 
        ! (1) Do Not Skip Any Sentence In The Problem Main Text
        ! (2) Check The Time Complexity Before Starting To Code
        ! (3) Check The Constraints
        ! (4) Do Some Tricky Tests
        ! (5) Click On Submit :\
        *_    Telegram :  @Doctor_code_lua    _*
    */