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

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


void solve()
{
	string s;
	cin>>s;
	int n=s.size();
	stack<char>st;
	st.push(s[0]);
	for(int i=1;i<n;i++)
	{
		string temp;
		int val=(s[i]-'0');
		while(!st.empty() && val>0 && (val-1)>(st.top()-'0'))
		{
			val--;
			temp+=st.top();
			st.pop();
		}
		st.push(('0'+val));
		for(int i=temp.size()-1;i>=0;i--)
		{
			st.push(temp[i]);
		}
	}	
	string ans;
	while(!st.empty())
	{
		ans+=st.top();
		st.pop();
	}
	reverse(ans.begin(),ans.end());
	cout<<ans;
}
signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	// t=1;
	while(t--)
	{
		solve();
		cout<<endl;
	}
}

Solution 2 (runtime: 62 ms):
#include<bits/stdc++.h>
#define ll long long 
#define lli long long int
#define lld long long double
#define ull unsigned long long 
 
#define mxt(a) *max_element(a.begin(),a.end()) 
#define mnt(a) *min_element(a.begin(),a.end())
 
#define mxti(a,i,j) *max_element(a.begin()+i+1,a.begin()+j+1) 
#define mnti(a,i,j) *min_element(a.begin()+i+1,a.begin()+j+1)
 
#define acm(v,i,j) accumulate(v.begin()+i+1,v.begin()+j+1,0ll)
 
//extract sub vector from main vector
//vector<int> sub_vector(main_vector.begin()+start_index,main_vector.begin()+end_index)
 
#define srt(a) sort(a.begin(),a.end()) 
#define rev(a) reverse(a.begin(),a.end()) 
#define all(a) a.begin(),a.end()
 
#define sp " "
#define nl '\n'
#define op(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
#define in(a,n) for(int i=0;i<n;i++) cin>>a[i]
 
#define mii map<int,int>
#define mis map<int,string>
#define msi map<string,int>
#define mci map<char,int>
#define mic map<int,char>
 
// pairs
#define pii  pair<int, int>
#define pll  pair<ll, ll>
#define pdd  pair<db, db>
#define mkp make_pair
#define f first
#define s second
 
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define vs vector<string>
#define vc vector<char>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define vvs vector<vector<string>>
#define vvc vector<vector<char>>
#define pb push_back
 
 
#define fre(x, a) for (auto &x : a)
#define fr(a,c,b) for(ll a=c;a<b;a++)
 
#define MOD 1000000007
const int MX = (int)2e5 + 5;
const ll BIG = 1e18;  // not too close to LLONG_MAX
 
const int dx[4]{1, 0, -1, 0}, dy[4]{0, 1, 0, -1};  // for every grid problem!!
 
#define PYES cout<<"YES\n"
#define PNO cout<<"NO\n"
#define PYes cout<<"Yes\n"
#define PNo cout<<"No\n"
 
 
 
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
     
   
using namespace std;
//--------------------------------------------DEBUG-------------------------------------------------//
#ifndef ONLINE_JUDGE
#define dg(x) cerr << #x <<" --> "; _print(x); cerr << endl;
#else
#define dg(x)
#endif

void _print(ll t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(ull t) { cerr << t; }

// Forward declarations for templates
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, class V> void _print(multimap <T, V> v);
template <class T> void _print(multiset <T> v);

// Definitions for templates
template <class T, class V> void _print(pair <T, V> p) {
    cerr << "{"; _print(p.first); cerr << ", "; _print(p.second); 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 << "}";
}

template <class T, class V> void _print(multimap <T, V> v) {
    cerr << "{ "; for (auto i : v) { _print(i); cerr << ", "; } cerr << "}";
}
 
//--------------------------------------------functions-------------------------------------------------//
 
ll power(ll a,ll b){
    ll result=1;
    while(b>0){
        if(b%2 == 1){
            result *= a;
        }
        a *= a;
        b /= 2;
    }
    return result;
}
ll gcd(ll x,ll y){
    ll r;
    while(y!=0&&(r=x%y)!=0){
        x=y;y=r;
    }
    return y==0?x:y;
}
ll countSetBits(ll x){ll Count=0;while(x>0){if(x&1) Count++;x=x>>1;}return Count;}
ll mod(ll x,ll M){return ((x%M + M)%M);}
ll add(ll a, ll b,ll M){return mod(mod(a,M)+mod(b,M),M);}
ll mul(ll a, ll b,ll M){return mod(mod(a,M)*mod(b,M),M);}
ll powerM(ll a,ll b,ll M){
    ll res=1ll;
    while(b){
        if(b%2ll==1ll){
            res=(a*res)%M;
        }
        a=(a*a)%M;b/=2ll;
    }
    return res;
}
ll mod_inv(ll a, ll m) {
    ll g = m, r = a, x = 0, y = 1;
    while (r != 0) {
        ll q = g / r;
        g %= r; swap(g, r);
        x -= q * y; swap(x, y);
    }
    return (x%m + m)%m;
}
 
 
////------------------------------------sieve of Eratosthenes-----------------------------------------------//
//ll MAXN=3e5;
//vector<ll> fact(MAXN+1);
//void sieve_of_erantothenes()
//{
//    fact[1] = 1;
//    for (ll i = 2; i <= MAXN; i++)
//        fact[i] = i;
//    for (ll i = 4; i <= MAXN; i += 2)
//        fact[i] = 2;
//    for (ll i = 3; i * i <= MAXN; i++){
//        if (fact[i] == i){
//            for (ll j = i * i; j <= MAXN; j += i)
//                if (fact[j] == j)
//                    fact[j] = i;
//        }
//    }
//}
//----------------------------------------nCr mod------------------------------------------------------//
ll nCr(ll n, ll k){
    if(n<k) return 0;
    if(k==0) return 1;
    ll res = 1;
    if (k > n - k) k = n - k;
    for(ll i = 0; i < k; ++i){
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}
 
vector<ll> FA,INV;
void fcalc(ll n,ll M){
    FA.resize(n+1);
    FA[0]=1;
    for(ll i=1;i<=n;i++){
        FA[i]=(FA[i-1]*i)%M;
    }
}
 
void icalc(ll n,ll M){
    INV.resize(n+1);
    INV[n]=mod_inv(FA[n],M);
    for(ll i=n-1;i>=0;i--){
        INV[i]=(INV[i+1]*(i+1))%M;
    }
}
ll nCrM(ll n,ll r,ll M){
    if(r<0) return 0;
    if(n<r) return 0;
    if(r==0) return 1;
    ll a=FA[n];
    a*=INV[r];
    a%=M;
    a*=INV[n-r];
    a%=M;
    return a;
}
ll mod_exp(ll base, ll exp, ll mod) {
    ll result = 1;
    while (exp > 0) {
        if (exp % 2 == 1) {
            result = (result * base) % mod;
        }
        base = (base * base) % mod;
        exp = exp / 2;
    }
    return result;
}
// ll rand_int(ll l, ll r){
//     return uniform_int_distribution<ll>(l, r)(rng);
// }

ifstream fin;
ofstream fout;
 
template <typename T>
ostream& operator <<(ostream& output, const vector<T>& data)
{
    for (const T& x : data)
        output << x <<" ";
    return output;
}
 
template<typename T>
istream& operator>>(istream& input,vector<T>& data){
    for (auto& item : data) {
        input >> item;
    }
    return input;
}
 
 
int LCM(int a, int b){
    return ((a * b) / gcd(a, b));
}
 
ll ceil(ll a, ll b){// a / b
    return a / b + ((a ^ b) > 0 && a % b);
}
//   bool inl(int i,int j,int m,int n){
//         return (i>=0 && j>=0 && i<m && j<n);
//       }
//--------------------------------------------solve----------------------------------------------//
bool isPerfectSquare(ll num) {
    if (num < 0) {
        return false;  
    }
 
    int sqrtValue = static_cast<int>(sqrt(num));
    return (sqrtValue * sqrtValue == num);
}


bool pred(ll mid) {
   return mid==(ll)sqrt(mid)*(ll)sqrt(mid);
}
vector<bool> isPrime(1e6+50,true);

void seive(){
    isPrime[0] = isPrime[1] = false;
    fr(i,2,1e3+1){
        if(isPrime[i]){
            for(ll j=i*i;j<=1e6;j+=i){
                isPrime[j]=false;
            }
        }
    }
}
void solve()
{
    int t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        ll n = s.size();
        ll k=10;
        while(k--){
            for (ll j = 1; j < n; j++)
            {

                if (s[j] - 1 > s[j - 1])
                {
                    s[j]--;
                    swap(s[j], s[j - 1]);
                }
            }
        }
        
        cout << s << nl;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    solve();
 
    return 0;
}