Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define nline "\n"
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define int long long
#define fr(a, b) for (int i = a; i < b; i++)
#define rep(i, a, b) for (int i = a; i < b; i++)


#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(double t) {cerr << t;}
vector<int> sieve(int n) {int*arr = new int[n + 1](); vector<int> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
int gcd(int a, int b) {
    while (b != 0) {
        int tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
        const int N = 2e5 + 5, mod = 1e9 + 7;
int binaryExpo(int a, int b) {
    int r = 1;
    while(b > 0) {
        if(b & 1) r = (r * a) % mod;
        b /= 2;
        a = (a * a) % mod; 
    }
    return r;
}
int modAdd(int a, int b, int m){
    return ((a%m)+(b%m))%m;
}
int modMul(int a, int b, int m){
    return (1ll*(a%m)*(b%m))%m;
}
int modSub(int a, int b, int m){
    return ((a%m)-(b%m)+m)%m;
}
int modInv(int a,int m){
    return (binaryExpo(a,m-2)%m);
}
int fact[N];
void init(){
    fact[0] = 1;
    for(int i = 1; i < N; ++i) fact[i] = (fact[i - 1] * i) % mod;
}
int C(int n, int k) {
    if(n < k) return 0LL;
    return (fact[n] * binaryExpo((fact[n - k] * fact[k]) % mod, mod - 2)) % mod;
}
void solve()
{
    int n;cin >>n;
    map<int,int>mp;
    int sum = 0;
    while(n>0){
        int d = n%10;
        if(d==2){
            mp[2]++;
        }
        else if(d==3){
            mp[6]++;
        }
        sum+=d;
        n/=10;
    }
    for(int tw=0;tw<=min(8ll,mp[2]);tw++){
        for(int th=0;th<=min(8ll,mp[6]);th++){
            int val = tw*2+th*6+sum;
            if(val%9==0){
                cout << "YES\n";return;
            }
        }
    }
    cout << "NO\n";

}
signed main()
{
       #ifndef ONLINE_JUDGE 
 freopen("input.txt", "r", stdin);
 freopen("error.txt", "w", stderr);
 freopen("output.txt", "w", stdout);
    #endif
 int t=1;
 cin >> t;
//  for(auto it : prime)
//     cout << it << " ";
// cout << endl;
 while(t--)
 {
    solve();
}
}