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

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

vector<bool> digitchanges(9);
 //track the digits already searched

bool searchchanges(int curmod9, int remaining2s, int remaining3s, int iterator){
    if(curmod9 == 0){
        return true;
    }
    if(iterator > 9){
        return false;
    }
    iterator++;
    // 1 2 3 4 5 6 7 8 0
    /*
    if(digitchanges[curmod9] == true){
        cout << curmod9 << "\n";
        return false;
    }
    */
    if(remaining2s == 0 && remaining3s == 0){
       // cout << remaining2s << " " << remaining3s << "\n";
        return false;
    }
    digitchanges[curmod9] = true;
    bool true2 = false;
    bool true3 = false;
    if(remaining2s > 0){
        int newmod9 = (2 + curmod9) % 9;
        true2 = searchchanges(newmod9, remaining2s-1, remaining3s, iterator);
    }
    if(remaining3s > 0){
        int newmod9 = (6+curmod9) % 9;
        true3 = searchchanges(newmod9, remaining2s, remaining3s-1, iterator);
    }
    if(true2 == true || true3 == true){
        return true;
    }
    return false;
}

void solve() {
    int n[2]; //only store twos and threes
    n[0] = 0; //count of 2s
    n[1] = 0; //count of 3s
    int totalmod9 = 0;
    string s;
    cin >> s;
    int len = s.length();
    for(int i = 0; i < len; i++){
        if(s[i] == '3'){
            n[1]++;
        }
        if(s[i] == '2'){
            n[0]++;
        }
        int digit = s[i] - '0';
        totalmod9 += digit;
        totalmod9 = totalmod9 % 9;
    }
    
    if(n[0] > 9){
        cout << "YES";
    } else if(n[0]>3&&n[1]>3){
        cout << "YES";
    } else if(n[1]>3 && totalmod9%3==0){
        cout << "YES";
    }else if(searchchanges(totalmod9, n[0], n[1], 0) == true){
        cout << "YES";
    } else{
        cout << "NO";
    }
    return;
}

int main() {
    int TESTS; cin >> TESTS;
    while (TESTS --> 0) {
        solve();
        cout << '\n';
    }
    return 0;
}

Solution 2 (runtime: 77 ms):
// Author: Youssef ben youssef
// Template for Competitive Programming

#include<utility>
#include<map>
#include<unordered_map>
#include<vector>
#include<set>
#include<ios>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<long long>;
using pi = pair<int, int>;
using pll = pair<long long, long long>;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const ld EPS = 1e-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) ((int)(x).size())
ll mod_exp(ll base, ll exp, ll mod = MOD) {
    ll res = 1;
    while (exp) {
        if (exp & 1) res = (res * base) % mod;
        base = (base * base) % mod;
        exp >>= 1;
    }
    return res;
}
ll min(ll a,int b) { if (a<b) return a; return b; }
ll min(int a,ll b) { if (a<b) return a; return b; }
ll max(ll a,int b) { if (a>b) return a; return b; }
ll max(int a,ll b) { if (a>b) return a; return b; }
ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); }
ll exgcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = exgcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; }
string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; }
bool prime(ll a) { if (a==1) return 0; for (int i=2;i<=round(sqrt(a));++i) if (a%i==0) return 0; return 1; }
void yes() { cout<<"YES\n"; }
void no() { cout<<"NO\n"; }
template <typename T>
void read(vector<T>& v) {
    for (auto& x : v) cin >> x;
}

template <typename T>
void print(const vector<T>& v) {
    for (const auto& x : v) cout << x << ' ';
    cout << '\n';
}
void solve() {
        string s;
        cin >> s;
        ll sum=0,twos=0,threes=0;
        for (auto i :s)
        {
            sum+= (i-'0');

            if(i=='2')twos++;
            if(i=='3')threes++;
            sum%=9;
        }
        for (ll i = 0; i <=min(10,twos); i++)
        {
            for (ll j = 0; j <= min(10,threes); j++)
            {
                ll tsum =1ll*sum+i*2+6*j;
                if(tsum%9==0){yes();return;}
            }
        }
        no();
}

int main() {
    fastio;
    int t;
    cin >> t;
    while (t--)
    {
        
        solve();
        

    }
    
    return 0;
}