Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
// Author: Ananyapam7

#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;

using namespace chrono;

//=============================================CONSTANTS=============================================

const int MOD = 1e9 + 7;

const long long phi_mod = 1e9 + 6;

const long long phi_phi_mod = 500000002855730640;

const long long inf = 1e18;

//==============================================MACROS===============================================

#define ll long long

#define ull unsigned long long

#define lld long long double

//==============================================TYPEDEFS=============================================

typedef pair<int, int> pii;

typedef pair<ll, ll>   pl;

typedef vector<int>    vi;

typedef vector<bool>   vb;

typedef vector<ll>     vl;

typedef vector<pii>    vpii;

typedef vector<pl>     vpl;

typedef vector<vi>     vvi;

typedef vector<vl>     vvl;

typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//==============================================FUNCTIONS============================================



#define fo(i,n)        for(ll i = 0; i < n; i++)

#define fr(i, a, b)    for (ll i = a; i < b; i++)

#define trav(a,v)      for(auto &a:v)

#define pb             push_back

#define mp             make_pair

#define ff             first

#define ss             second

#define clr(x)         memset(x, 0, sizeof(x))

#define all(a)         a.begin(), a.end()

#define rall(a)        a.rbegin(),a.rend()

#define sortall(x)     sort(all(x))

#define nl             cout<<endl



//Vectors

#define count_element(a, x)  ( count(a.begin(), a.end(), x))

#define sum(a)               ( accumulate ((a).begin(), (a).end(), 0ll))

#define mine(a)              (*min_element((a).begin(), (a).end()))

#define maxe(a)              (*max_element((a).begin(), (a).end()))

#define max_pos(a)           ((max_element((a).begin(), (a).end())) - a.begin())

#define min_pos(a)           ((min_element((a).begin(), (a).end())) - a.begin())



//Math

mt19937 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());

// #define gcd(a, b)       __gcd(a, b)

#define lcm(a, b)       (a * b) / gcd(a, b)

ll gcd(ll a,ll b){if(b==0LL)return a;return gcd(b,a%b);}

#define pow2(x)         (1ll<<(x))

ll power(ll x, ll k){

    ll ans=x;

    for(ll i=1;i<k;i++){

        ans*=x;

    }

    return ans;

}

ll int_sqrt (ll x) {ll ans = 0;for (ll k = 1LL << 30; k != 0; k /= 2) {if ((ans + k) * (ans + k) <= x) {ans += k;}}return ans;}

int highestPowerOf2(int n){return (n & (~(n - 1)));}

ll mpow(ll a, ll b, ll MOD) {ll res = 1; while (b > 0){if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b >>= 1; } return res; }

ll inv(ll a, ll MOD) {return mpow(a, MOD - 2, MOD);}

void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an array of size 3

bool isPrime(ll n) {if (n == 2 || n == 3 || n == 5) {return true; } if (n % 2 == 0 || n % 3 == 0) {return false; } for (ll i=5; i*i<=n; i=i+6) {if (n%i == 0 || n%(i+2) == 0) {return false; } } return true; }

bool issquare(ll n) {if (n >= 0) {ll sr = static_cast<ll>(std::sqrt(n));;return ((sr * sr) == n);}return false;}

ll factorial(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = (res * i) % MOD ;return res;}

// ll phi(ll n){ll result = n;for(ll p = 2; p * p <= n; ++p){if (n % p == 0){while (n % p == 0)n /= p;result -= result / p;}}if (n > 1)result -= result / n;return result;}

ll findMex(vector<int> arr){int mex = 0; for (auto& i:arr) {if (i == mex) {mex++; } } return mex; }

vl divisors(ll n){vl v;for (ll i=1; i*i<=(n); i++){if (n%i == 0){v.pb(i);if (n/i!=i)v.pb(n/i);}}return v;}

ll count_divisors(ll n){ll count=0;for(int i=1;i*1LL*i<=n;i++){if(n%i==0){count++;if(i!=n/i){count++;}}}return count;}

ll digit_sum(ll n){string s = to_string(n);ll ans=0;for(auto &x:s){ans+=x-'0';}return ans;}

bool isPalindrome(ll num) {ll originalNum = num;ll reversedNum = 0;while (num > 0) {reversedNum = reversedNum * 10 + num % 10;num /= 10;}return originalNum == reversedNum;}

vector<int> phi_1_to_n(int n) {

    vector<int> phi(n + 1);

    for (int i = 0; i <= n; i++)

        phi[i] = i;

 

    for (int i = 2; i <= n; i++) {

        if (phi[i] == i) {

            for (int j = i; j <= n; j += i)

                phi[j] -= phi[j] / i;

        }

    }

 

    return phi;

}



// Sieve

const int N = 200001;

int spf[N];

void sieve() {

    for (int i = 1; i < N; ++i)spf[i] = i;

    for (int i = 2; i < N; ++i) {

        for (int j = 2*i; j < N; j+=i) {

            if(spf[j]==j)spf[j]=i;

        }

    }

}



ll comb(int n, int k) {

    if (k==0) return 1LL;

    ll ans=1;

    for (int i=n-k+1; i<=n; ++i) {

        ans*=i;

    }

    for (int i=1; i<=k; ++i) {

        ans/=i;

    }

    return ans;

}



// Combinarotics

// const int MOD = 1e9 + 7;

// const int MOD = 998244353;

// const long long MOD = 1375927501846395853LL;

// template<const int mod>

// struct mint {

//     int val;

//     constexpr mint(long long x = 0) : val((x % mod + mod) % mod) {}

//     explicit operator int() const { return val; }

//     mint& operator+=(const mint &b) { val += b.val; val -= mod * (val >= mod); return *this; }

//     mint& operator-=(const mint &b) { val -= b.val; val += mod * (val < 0); return *this; }

//     mint& operator*=(const mint &b) { val = 1ll * val * b.val % mod; return *this; }

//     mint& operator/=(const mint &b) { return *this *= b.inv(); }

//     mint inv() const { int x = 1, y = 0, t; for(int a=val, b=mod; b; swap(a, b), swap(x, y)) t = a/b, a -= t * b, x -= t * y; return mint(x); }

//     mint power(int b) const { mint a = *this, res(1); for(; b; a *= a, b /= 2)  if(b & 1) res *= a; return res; }

//     mint operator-() const { return val == 0 ? 0 : mod - val; }

//     mint& operator++() { val = val == mod - 1 ? 0 : val + 1; return *this; }

//     mint& operator--() { val = val == 0 ? mod - 1 : val - 1; return *this; }

//     mint operator++(int32_t) { mint before = *this; ++*this; return before; }

//     mint operator--(int32_t) { mint before = *this; --*this; return before; }

//     friend mint operator+(const mint &a, const mint &b) {return mint(a) += b;}

//     friend mint operator-(const mint &a, const mint &b) {return mint(a) -= b;}

//     friend mint operator*(const mint &a, const mint &b) {return mint(a) *= b;}

//     friend mint operator/(const mint &a, const mint &b) {return mint(a) /= b;}

//     friend bool operator==(const mint &a, const mint &b) {return a.val == b.val;}

//     friend bool operator!=(const mint &a, const mint &b) {return a.val != b.val;}

//     friend bool operator<(const mint &a, const mint &b) {return a.val < b.val;}

//     friend istream& operator>>(istream &in, mint &a) {return in >> a.val;}

//     friend ostream& operator<<(ostream &os, const mint &a) {return os << a.val;}

// };

// using Mint = mint<MOD>;



// namespace comb {

//     int n(0);

//     vector<Mint> _fac{1}, _invfac{1}, _inv{0};

//     void init(int m) {

//         m = min (m, MOD - 1);

//         if (m <= n) return;

//         _fac.resize(m + 1); _invfac.resize(m + 1); _inv.resize(m + 1);

//         for (int i = n + 1; i <= m; i++) _fac[i] = _fac[i - 1] * i;

//         _invfac[m] = _fac[m].inv();

//         for (int i = m; i > n; i--) _invfac[i - 1] = _invfac[i] * i, _inv[i] = _invfac[i] * _fac[i - 1];

//         n = m;

//     }

//     Mint fac(int m) { if (m > n) init(2 * m); return _fac[m]; }

//     Mint invfac(int m) { if (m > n) init(2 * m); return _invfac[m]; }

//     Mint inv(int m) { if (m > n) init(2 * m); return _inv[m]; }

//     Mint ncr(int n, int r) { if (n < r || r < 0) return 0; return fac(n) * invfac(r) * invfac(n - r); }

// }

// using comb::fac, comb::invfac, comb::inv, comb::ncr;



//Strings

#define toUpperString(s)        transform(s.begin(), s.end(), s.begin(), ::toupper);

#define toLowerString(s)        transform(s.begin(), s.end(), s.begin(), ::tolower);

#define precision(a)            cout << fixed << setprecision(a)

#define sz(x)                   (int)((x).size())



//Hashing

long long setHashFunction(const string& str) {

    // maps '123' and '321' to the same value

    long long hashValue = 0;

    long long H = 62;

    long long K = 3344556;



    for (char x : str) {

        hashValue = (hashValue + mpow(x + K, H, MOD) % MOD) % MOD;

    }



    return hashValue;

}



//Standard input

#define si(x)  scanf("%d",&x)

#define sl(x)  scanf("%lld",&x)



//Standard output

#define pi(x)  printf("%d",x)

#define pl(x)  printf("%lld",x)

#define ps(s)  printf("%s",s)



//Graphs

ll dx[4] = {1,-1,1,-1};

ll dy[4] = {1,1,-1,-1};

// vector<pair<ll, ll>> movements = {{0,1}, {0,-1}, {1, 0}, {-1, 0}};

// bool isvalid(ll i, ll j, ll n, ll m){return i>=0 && j>=0 && i<n && j<m;}



//Strings

// vector<char> letter =           {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

// 0, 4, 8, 14, 20 (positions of vowels)

// vector<char> vowel  =           {'a', 'e', 'i', 'o', 'u'};



//=============================================TEMPLATES=============================================

template<typename T> // cin >> vector

istream &operator>>(istream &istream, vector<T> &v) { for (auto &it : v) { cin >> it; } return istream; }

template<typename T> // cout << vector

ostream &operator<<(ostream &ostream, const vector<T> &c) { for (auto &it : c) { cout << it << " "; } return ostream; }

//=============================================DEBUGGING=============================================

void __print(int x) {cerr << x;}

void __print(long x) {cerr << x;}

void __print(long long x) {cerr << x;}

void __print(unsigned x) {cerr << x;}

void __print(unsigned long x) {cerr << x;}

void __print(unsigned long long x) {cerr << x;}

void __print(float x) {cerr << x;}

void __print(double x) {cerr << x;}

void __print(long double x) {cerr << x;}

void __print(char x) {cerr << '\'' << x << '\'';}

void __print(const char *x) {cerr << '"' << x << '"';}

void __print(const string &x) {cerr << '"' << x << '"';}

void __print(bool x) {cerr << (x ? "true" : "false");}

 

template<typename T, typename V>

void __print(const pair<T, V> &x) {cerr << '['; __print(x.first); cerr << ','; __print(x.second); cerr << ']';}

template<typename T>

void __print(const T &x) {int f = 0; cerr << '['; for (auto &i: x) cerr << (f++ ? " ," : ""), __print(i); cerr << ']';}

void _print() {cerr << "\n";}

template <typename T, typename... V>

void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

 

#ifndef ONLINE_JUDGE

#define deb(x...) cerr << #x << " = "; _print(x)

#else

#define deb(x...)

#endif





void solve(int t){

    string s; cin >> s;

    int n = s.size();

    for(int i=0;i<n;i++){

        int largest = s[i]-'0';

        int largest_pos=i;

        for(int j=i;j<min(n, i+10);j++){

            if(s[j]-'0'-(j-i) > largest){

                largest = s[j]-'0'-(j-i);

                largest_pos = j;

            }

            while(largest_pos>i){

                swap(s[largest_pos-1], s[largest_pos]);

                largest_pos--;

            }

        }

        s[i] = char(largest + '0');

    }

    cout<<s<<endl;

}



int main() {

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    #ifndef ONLINE_JUDGE

    freopen("error.txt", "w", stderr);

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

    #endif

    int t = 1;

    auto start1 = high_resolution_clock::now();

    cin >> t;

    for(int i=1;i<=t;i++) {

        solve(i);

    }

    auto stop1 = high_resolution_clock::now();

    auto duration = duration_cast<microseconds>(stop1 - start1);

    #ifndef ONLINE_JUDGE

        cerr << "Time: " << duration . count() / 1000 << endl;

    #endif

    return 0;

}

Submission (verdict: Accepted):
// Author: Ananyapam7

#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;

using namespace chrono;

//=============================================CONSTANTS=============================================

const int MOD = 1e9 + 7;

const long long phi_mod = 1e9 + 6;

const long long phi_phi_mod = 500000002855730640;

const long long inf = 1e18;

//==============================================MACROS===============================================

#define ll long long

#define ull unsigned long long

#define lld long long double

//==============================================TYPEDEFS=============================================

typedef pair<int, int> pii;

typedef pair<ll, ll>   pl;

typedef vector<int>    vi;

typedef vector<bool>   vb;

typedef vector<ll>     vl;

typedef vector<pii>    vpii;

typedef vector<pl>     vpl;

typedef vector<vi>     vvi;

typedef vector<vl>     vvl;

typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//==============================================FUNCTIONS============================================



#define fo(i,n)        for(ll i = 0; i < n; i++)

#define fr(i, a, b)    for (ll i = a; i < b; i++)

#define trav(a,v)      for(auto &a:v)

#define pb             push_back

#define mp             make_pair

#define ff             first

#define ss             second

#define clr(x)         memset(x, 0, sizeof(x))

#define all(a)         a.begin(), a.end()

#define rall(a)        a.rbegin(),a.rend()

#define sortall(x)     sort(all(x))

#define nl             cout<<endl



//Vectors

#define count_element(a, x)  ( count(a.begin(), a.end(), x))

#define sum(a)               ( accumulate ((a).begin(), (a).end(), 0ll))

#define mine(a)              (*min_element((a).begin(), (a).end()))

#define maxe(a)              (*max_element((a).begin(), (a).end()))

#define max_pos(a)           ((max_element((a).begin(), (a).end())) - a.begin())

#define min_pos(a)           ((min_element((a).begin(), (a).end())) - a.begin())



//Math

mt19937 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());

// #define gcd(a, b)       __gcd(a, b)

#define lcm(a, b)       (a * b) / gcd(a, b)

ll gcd(ll a,ll b){if(b==0LL)return a;return gcd(b,a%b);}

#define pow2(x)         (1ll<<(x))

ll power(ll x, ll k){

    ll ans=x;

    for(ll i=1;i<k;i++){

        ans*=x;

    }

    return ans;

}

ll int_sqrt (ll x) {ll ans = 0;for (ll k = 1LL << 30; k != 0; k /= 2) {if ((ans + k) * (ans + k) <= x) {ans += k;}}return ans;}

int highestPowerOf2(int n){return (n & (~(n - 1)));}

ll mpow(ll a, ll b, ll MOD) {ll res = 1; while (b > 0){if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b >>= 1; } return res; }

ll inv(ll a, ll MOD) {return mpow(a, MOD - 2, MOD);}

void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an array of size 3

bool isPrime(ll n) {if (n == 2 || n == 3 || n == 5) {return true; } if (n % 2 == 0 || n % 3 == 0) {return false; } for (ll i=5; i*i<=n; i=i+6) {if (n%i == 0 || n%(i+2) == 0) {return false; } } return true; }

bool issquare(ll n) {if (n >= 0) {ll sr = static_cast<ll>(std::sqrt(n));;return ((sr * sr) == n);}return false;}

ll factorial(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = (res * i) % MOD ;return res;}

// ll phi(ll n){ll result = n;for(ll p = 2; p * p <= n; ++p){if (n % p == 0){while (n % p == 0)n /= p;result -= result / p;}}if (n > 1)result -= result / n;return result;}

ll findMex(vector<int> arr){int mex = 0; for (auto& i:arr) {if (i == mex) {mex++; } } return mex; }

vl divisors(ll n){vl v;for (ll i=1; i*i<=(n); i++){if (n%i == 0){v.pb(i);if (n/i!=i)v.pb(n/i);}}return v;}

ll count_divisors(ll n){ll count=0;for(int i=1;i*1LL*i<=n;i++){if(n%i==0){count++;if(i!=n/i){count++;}}}return count;}

ll digit_sum(ll n){string s = to_string(n);ll ans=0;for(auto &x:s){ans+=x-'0';}return ans;}

bool isPalindrome(ll num) {ll originalNum = num;ll reversedNum = 0;while (num > 0) {reversedNum = reversedNum * 10 + num % 10;num /= 10;}return originalNum == reversedNum;}

vector<int> phi_1_to_n(int n) {

    vector<int> phi(n + 1);

    for (int i = 0; i <= n; i++)

        phi[i] = i;

 

    for (int i = 2; i <= n; i++) {

        if (phi[i] == i) {

            for (int j = i; j <= n; j += i)

                phi[j] -= phi[j] / i;

        }

    }

 

    return phi;

}



// Sieve

const int N = 200001;

int spf[N];

void sieve() {

    for (int i = 1; i < N; ++i)spf[i] = i;

    for (int i = 2; i < N; ++i) {

        for (int j = 2*i; j < N; j+=i) {

            if(spf[j]==j)spf[j]=i;

        }

    }

}



ll comb(int n, int k) {

    if (k==0) return 1LL;

    ll ans=1;

    for (int i=n-k+1; i<=n; ++i) {

        ans*=i;

    }

    for (int i=1; i<=k; ++i) {

        ans/=i;

    }

    return ans;

}



// Combinarotics

// const int MOD = 1e9 + 7;

// const int MOD = 998244353;

// const long long MOD = 1375927501846395853LL;

// template<const int mod>

// struct mint {

//     int val;

//     constexpr mint(long long x = 0) : val((x % mod + mod) % mod) {}

//     explicit operator int() const { return val; }

//     mint& operator+=(const mint &b) { val += b.val; val -= mod * (val >= mod); return *this; }

//     mint& operator-=(const mint &b) { val -= b.val; val += mod * (val < 0); return *this; }

//     mint& operator*=(const mint &b) { val = 1ll * val * b.val % mod; return *this; }

//     mint& operator/=(const mint &b) { return *this *= b.inv(); }

//     mint inv() const { int x = 1, y = 0, t; for(int a=val, b=mod; b; swap(a, b), swap(x, y)) t = a/b, a -= t * b, x -= t * y; return mint(x); }

//     mint power(int b) const { mint a = *this, res(1); for(; b; a *= a, b /= 2)  if(b & 1) res *= a; return res; }

//     mint operator-() const { return val == 0 ? 0 : mod - val; }

//     mint& operator++() { val = val == mod - 1 ? 0 : val + 1; return *this; }

//     mint& operator--() { val = val == 0 ? mod - 1 : val - 1; return *this; }

//     mint operator++(int32_t) { mint before = *this; ++*this; return before; }

//     mint operator--(int32_t) { mint before = *this; --*this; return before; }

//     friend mint operator+(const mint &a, const mint &b) {return mint(a) += b;}

//     friend mint operator-(const mint &a, const mint &b) {return mint(a) -= b;}

//     friend mint operator*(const mint &a, const mint &b) {return mint(a) *= b;}

//     friend mint operator/(const mint &a, const mint &b) {return mint(a) /= b;}

//     friend bool operator==(const mint &a, const mint &b) {return a.val == b.val;}

//     friend bool operator!=(const mint &a, const mint &b) {return a.val != b.val;}

//     friend bool operator<(const mint &a, const mint &b) {return a.val < b.val;}

//     friend istream& operator>>(istream &in, mint &a) {return in >> a.val;}

//     friend ostream& operator<<(ostream &os, const mint &a) {return os << a.val;}

// };

// using Mint = mint<MOD>;



// namespace comb {

//     int n(0);

//     vector<Mint> _fac{1}, _invfac{1}, _inv{0};

//     void init(int m) {

//         m = min (m, MOD - 1);

//         if (m <= n) return;

//         _fac.resize(m + 1); _invfac.resize(m + 1); _inv.resize(m + 1);

//         for (int i = n + 1; i <= m; i++) _fac[i] = _fac[i - 1] * i;

//         _invfac[m] = _fac[m].inv();

//         for (int i = m; i > n; i--) _invfac[i - 1] = _invfac[i] * i, _inv[i] = _invfac[i] * _fac[i - 1];

//         n = m;

//     }

//     Mint fac(int m) { if (m > n) init(2 * m); return _fac[m]; }

//     Mint invfac(int m) { if (m > n) init(2 * m); return _invfac[m]; }

//     Mint inv(int m) { if (m > n) init(2 * m); return _inv[m]; }

//     Mint ncr(int n, int r) { if (n < r || r < 0) return 0; return fac(n) * invfac(r) * invfac(n - r); }

// }

// using comb::fac, comb::invfac, comb::inv, comb::ncr;



//Strings

#define toUpperString(s)        transform(s.begin(), s.end(), s.begin(), ::toupper);

#define toLowerString(s)        transform(s.begin(), s.end(), s.begin(), ::tolower);

#define precision(a)            cout << fixed << setprecision(a)

#define sz(x)                   (int)((x).size())



//Hashing

long long setHashFunction(const string& str) {

    // maps '123' and '321' to the same value

    long long hashValue = 0;

    long long H = 62;

    long long K = 3344556;



    for (char x : str) {

        hashValue = (hashValue + mpow(x + K, H, MOD) % MOD) % MOD;

    }



    return hashValue;

}



//Standard input

#define si(x)  scanf("%d",&x)

#define sl(x)  scanf("%lld",&x)



//Standard output

#define pi(x)  printf("%d",x)

#define pl(x)  printf("%lld",x)

#define ps(s)  printf("%s",s)



//Graphs

ll dx[4] = {1,-1,1,-1};

ll dy[4] = {1,1,-1,-1};

// vector<pair<ll, ll>> movements = {{0,1}, {0,-1}, {1, 0}, {-1, 0}};

// bool isvalid(ll i, ll j, ll n, ll m){return i>=0 && j>=0 && i<n && j<m;}



//Strings

// vector<char> letter =           {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

// 0, 4, 8, 14, 20 (positions of vowels)

// vector<char> vowel  =           {'a', 'e', 'i', 'o', 'u'};



//=============================================TEMPLATES=============================================

template<typename T> // cin >> vector

istream &operator>>(istream &istream, vector<T> &v) { for (auto &it : v) { cin >> it; } return istream; }

template<typename T> // cout << vector

ostream &operator<<(ostream &ostream, const vector<T> &c) { for (auto &it : c) { cout << it << " "; } return ostream; }

//=============================================DEBUGGING=============================================

void __print(int x) {cerr << x;}

void __print(long x) {cerr << x;}

void __print(long long x) {cerr << x;}

void __print(unsigned x) {cerr << x;}

void __print(unsigned long x) {cerr << x;}

void __print(unsigned long long x) {cerr << x;}

void __print(float x) {cerr << x;}

void __print(double x) {cerr << x;}

void __print(long double x) {cerr << x;}

void __print(char x) {cerr << '\'' << x << '\'';}

void __print(const char *x) {cerr << '"' << x << '"';}

void __print(const string &x) {cerr << '"' << x << '"';}

void __print(bool x) {cerr << (x ? "true" : "false");}

 

template<typename T, typename V>

void __print(const pair<T, V> &x) {cerr << '['; __print(x.first); cerr << ','; __print(x.second); cerr << ']';}

template<typename T>

void __print(const T &x) {int f = 0; cerr << '['; for (auto &i: x) cerr << (f++ ? " ," : ""), __print(i); cerr << ']';}

void _print() {cerr << "\n";}

template <typename T, typename... V>

void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

 

#ifndef ONLINE_JUDGE

#define deb(x...) cerr << #x << " = "; _print(x)

#else

#define deb(x...)

#endif





void solve(int t){

    string s; cin >> s;

    int n = s.size();

    for(int i=0;i<n;i++){

        int largest = s[i]-'0';

        int largest_pos=i;

        for(int j=i;j<min(n, i+10);j++){

            if(s[j]-'0'-(j-i) > largest){

                largest = s[j]-'0'-(j-i);

                largest_pos = j;

            }

        }

        while(largest_pos>i){

            swap(s[largest_pos-1], s[largest_pos]);

            largest_pos--;

        }

        s[i] = char(largest + '0');

    }

    cout<<s<<endl;

}



int main() {

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    #ifndef ONLINE_JUDGE

    freopen("error.txt", "w", stderr);

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

    #endif

    int t = 1;

    auto start1 = high_resolution_clock::now();

    cin >> t;

    for(int i=1;i<=t;i++) {

        solve(i);

    }

    auto stop1 = high_resolution_clock::now();

    auto duration = duration_cast<microseconds>(stop1 - start1);

    #ifndef ONLINE_JUDGE

        cerr << "Time: " << duration . count() / 1000 << endl;

    #endif

    return 0;

}