Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 61 ms):
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type, less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<typename T>
void pl(const T& m) {
    cout << m << endl;
}
template<typename T>
void ps(const T& m) {
    cout << m <<" ";
}
template<typename T>
void p(const T& m) {
    cout << m;
}
//Aliases
using ll= long long;
using lld= long double;
using ull= unsigned long long;

//Constants
const lld pi= 3.141592653589793238;
const ll INF= LONG_LONG_MAX;
const ll mod=1e9+7;

//TypeDEf
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll,ll> umll;
typedef map<ll,ll> mll;
typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, 
less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;
// Macros
#define nl cout<<endl
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define fl(i,n) for(int i=0;i<n;i++)
#define fll(i,m,n) for(int i=m;i<=n;i++)
#define rl(i,n,m) for(int i=n;i>=m;i--)
#define py cout<<"YES\n"
#define pm cout<<"-1\n"
#define pn cout<<"NO\n"
#define pimp cout<<"IMPOSSIBLE\n";
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define rv(v) v.end(),v.begin()

ll modAdd(ll a, ll b, ll m) {
    return ((a % m) + (b % m)) % m;
}

ll modSub(ll a, ll b, ll m) {
    return ((a % m) - (b % m) + m) % m;
}

ll modMul(ll a, ll b, ll m) {
    return ((a % m) * (b % m)) % m;
}

ll modpow(ll x, ll y, ll p) {
    ll 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;
}

ll modInverse(ll a, ll m) {
    return modpow(a, m - 2, m);
}

ll modDiv(ll a, ll b, ll m) {
    a = a % m;
    ll inv = modInverse(b, m);
    return (inv * a) % m;
}
void testcase()
{
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        char maxi=s[i];
        int idx=i;
        for(int j=i+1;j<i+9;j++)
        {
            if(j>=s.size()) break;
            if(s[j]-(j-i)>maxi)
            {
                maxi=s[j]-(j-i);
                idx=j;
            }
        }
        s[idx]=maxi;
        while(idx>i)
        {
            swap(s[idx],s[idx-1]);
            idx--;
        }
    }
    pl(s);
    
}
    
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    fl(i,t)
    testcase();
    return 0;
}

Solution 2 (runtime: 93 ms):
#include <bits/stdc++.h>

using namespace std;

#define ll long long

void solve() {

string s;

cin >> s;

if(s.length() == 1) {

cout << s << endl;

return;

}

while(true) {

bool flag = false;

for(ll i=1; i<s.length(); i++) {

if((s[i] != '0') && ((s[i-1] < (s[i] - 1)))) {

flag = true;

s[i] -= 1;

char tmp = s[i];

s[i] = s[i-1];

s[i-1] = tmp;

}

}

if(!flag) break;

}

cout << s << endl;

}

int main() {

int t;

cin >> t;

while(t--) solve();

return 0;

}