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

Solution 1 (runtime: 62 ms):
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        string g;
        cin>>g;
        int c2=0;
        int c3=0;
        int s=0;
        for(int i=0;i<g.length();i++){
            int d=g[i]-'0';
            if(d==2) c2++;
            if(d==3) c3++;
            s+=d;
        }
        if(s%9==0) cout<<"yes"<<endl;
        else if(s%9==8&&((c2>=2&&c3>=1)||c2>=5)) cout<<"yes"<<endl;
        else if(s%9==7&&c2>=1) cout<<"yes"<<endl;
        else if(s%9==6&&(c2>=6||c3>=2||(c3>=1&&c2>=3))) cout<<"yes"<<endl;
        else if(s%9==5&&c2>=2) cout<<"yes"<<endl;
        else if(s%9==4&&(c2>=7||(c2>=1&&c3>=2)||(c2>=4&&c3>=1))) cout<<"yes"<<endl;
        else if(s%9==3&&((c3>=1||c2>=3)||c2>=6)) cout<<"yes"<<endl;
        else if(s%9==2&&(c3>=2&&c2>=2)||((c3>=1&&c2>=5)||(c2>=8))) cout<<"yes"<<endl;
        else if(s%9==1&&((c3>=1&&c2>=1)||c2>=4)) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}

Solution 2 (runtime: 62 ms):
// Problem Link -
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ld long double
#define mod 1000000007
#define inf 1e18
#define endl "\n"
#define pb push_back
#define pi pair<ll, ll>
#define vi vector<ll>
#define vpi vector<pi>
#define vvi vector<vi>
#define vvpi vector<vector<pi>>
#define vs vector<string>
#define ump unordered_map
#define pq_max priority_queue<ll>
#define pq_min priority_queue<ll, vi, greater<ll>>
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define mid(l, r) (l + (r - l) / 2)
#define loop(i, a, b) for (ll i = (a); i <= (b); i++)
#define looprev(i, a, b) for (ll i = (a); i >= (b); i--)
#define log(args...)                             \
    {                                            \
        string _s = #args;                       \
        replace(_s.begin(), _s.end(), ',', ' '); \
        stringstream _ss(_s);                    \
        istream_iterator<string> _it(_ss);       \
        err(_it, args);                          \
    }
#define logarr(arr, a, b)            \
    for (int z = (a); z <= (b); z++) \
        cout << (arr[z]) << " ";     \
    cout << endl;
#define token(str, ch) (std::istringstream var((str)); vs v; string t; while (getline((var), t, (ch))) { v.pb(t); } return v;)
vs tokenizer(string str, char ch)
{
    std::istringstream var((str));
    vs v;
    string t;
    while (getline((var), t, (ch)))
    {
        v.pb(t);
    }
    return v;
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cout << *it << " = " << a << endl;
    err(++it, args...);
}
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void file_i_o()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int main(int argc, char const *argv[])
{
    // file_i_o();

    ll t;
    cin >> t;

    while (t--)
    {
        string s;
        cin>>s;

        ll cnt2=0,cnt3=0,sum=0;

        for(auto c:s)
        {
            sum+=c-'0';
            if(c=='2') cnt2++;
            if(c=='3') cnt3++;
        }
        sum%=9;
        sum=9-sum;
        if(sum%9==0)
        {
            cout<<"YES\n";
            continue;
        }
        if(sum%2==1) sum+=9;

        sum/=2;
        // log(sum,cnt2,cnt3);
        while(sum>0 and sum>=3 and cnt2<sum and cnt3>0)
        {
            sum-=3;
            cnt3--;
        }
        if(sum==0 or cnt2>=sum)
        {
            cout<<"YES\n";
        }
        else{
            cout<<"NO\n";
        }
    }

    return 0;
}