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

Solution 1 (runtime: 62 ms):
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define countBits(x) __buitlin_popcount(x)
using namespace std;



class DisjointSet{
    public:
    vector<int> rank,size,par;
 
    DisjointSet(int n){
      rank.resize(n+1,0);
      par.resize(n+1);
      size.resize(n+1,1);
      for(int i=0;i<=n;i++){par[i]=i;}
    }
    int findupar(int v){
      if(par[v]==v)return v;
      
      return par[v]=findupar(par[v]);
    }
    
    void unionbyrank(int u,int v){
         int upu=findupar(u);
         int upv=findupar(v);
         if(upu==upv)return;
         
         if(rank[upu]>rank[upv]){
          par[upv]=upu;
         }
         else if(rank[upu]<rank[upv]){
          par[upu]=upv;
         }
         else{
          rank[upu]++;
          par[upv]=upu;
         }
    }
    void unionbysize(int u,int v){
         int upu=findupar(u);
         int upv=findupar(v);
         if(upu==upv)return;
         if(size[upu]>size[upv]){
          par[upv]=upu;
          size[upu]+=size[upv];
         }
         else{
          par[upu]=upv;
          size[upv]+=size[upu];
         }
    }
};



class SGTree{
	vector<int>seg;
	public:
		SGTree(int n){
		seg.resize(4*n+1);
	}
	void build(int ind, int low, int  high, int arr[]){
		if(low==high){
			seg[ind]=arr[low];
			return;
		}
		int mid=(low+high)/2;
		build(2*ind+1,low,mid,arr);
		build(2*ind+2,mid+1,high,arr);
		seg[ind]=min(seg[2*ind+1],seg[2*ind+2]);
	}

	int query(int ind,int low,int high,int l,int r){
		// no overlapping
		if(high<l || r<low) return INT_MAX;

		// complete overlapping
		if(low>=l && high<=r) return seg[ind];

		// partial overlap
		
		int mid=(low+high)/2;
		int left=query(2*ind+1,low,mid,l,r);
		int right=query(2*ind+2,mid+1,high,l,r);
		return min(left,right);
		
	}
	void update(int ind,int low,int high,int val,int i){
		if(low==high){
			seg[ind]=val;
			return;
		}

		int mid=(low+high)/2;
		if(i<=mid) update(2*ind+1,low,mid,val,i);
		else update(2*ind+2,mid+1,high,val,i);
		seg [ind]=min(seg[2*ind+1],seg[2*ind+2]);
	}
};
class ST{
public:
	vector<int>st,lazy;
public:
	get(){
		cout<<st[0]<<endl;
	}
public:
	ST(int n){
		st.resize(4*n);
		lazy.resize(4*n);
	}
public:
	void build(int ind, int low,int high,int arr[]){
		if(low==high){
			st[ind]=arr[low];
			return;
		}
		int mid=(low+high)/2;
		build(2*ind+1,low,mid,arr);
		build(2*ind+2,mid+1,high,arr);
		st[ind]=st[2*ind+1]+st[2*ind+2];
	}
public:
	void update(int ind,int low,int high,int l,int r,int val){
		// updates previous 
		// lazy propogates down
		if(lazy[ind]!=0){
			st[ind]+=(high-low+1)*lazy[ind];
			if(low!=high){
				lazy[2*ind+1]+=lazy[ind];
				lazy[2*ind+2]=lazy[ind];
			}
			lazy[ind]=0;
		}

		// no overlap 
		if(high<l || low>r) return ;
		if(low>=l && high<=r) {
			st[ind]+=(high-low+1)*val;
			if(low!=high){
				lazy[2*ind+1]+=val;
				lazy[2*ind+2]+=val;
			}
			return ;
		}
		int mid=(low+high)/2;
		update(2*ind+1,low,mid,l,r,val);
		update(2*ind+2,mid+1,high,l,r,val);
		st[ind]=st[2*ind+1]+st[2*ind+2]; 
	}
public:
	int query(int ind,int low,int high,int l,int r){
		// upadtes if updates are remaining
		if(lazy[ind]!=0){
			st[ind]+=(high-low+1)*lazy[ind];
			if(low!=high){
				lazy[2*ind+1]+=lazy[ind];
				lazy[2*ind+2]+=lazy[ind];
			}
			lazy[ind]=0;
		}


		// no overlap 
		if(high<l || low>r) return 0;
		if(low>=l && high<=r) {
			return st[ind];
		}
		int mid=(low+high)/2;
		int left=query(2*ind+1,low,mid,l,r);
		int right=query(2*ind+2,mid+1,high,l,r);
		return left+right;
	}
};

class STMin{
public:
	vector<int>st,lazy;
public:
	get(){
		cout<<st[0]<<endl;
	}
public:
	STMin(int n){
		st.resize(4*n);
		lazy.resize(4*n);
	}
public:
	void build(int ind, int low,int high,int arr[]){
		if(low==high){
			st[ind]=arr[low];
			return;
		}
		int mid=(low+high)/2;
		build(2*ind+1,low,mid,arr);
		build(2*ind+2,mid+1,high,arr);
		st[ind]=min(st[2*ind+1],st[2*ind+2]);
	}
public:
	void update(int ind,int low,int high,int l,int r,int val){
		// updates previous 
		// lazy propogates down
		if(lazy[ind]!=0){
			st[ind]+=lazy[ind];
			if(low!=high){
				lazy[2*ind+1]+=lazy[ind];
				lazy[2*ind+2]=lazy[ind];
			}
			lazy[ind]=0;
		}

		// no overlap 
		if(high<l || low>r) return ;
		if(low>=l && high<=r) {
			st[ind]+=val;
			if(low!=high){
				lazy[2*ind+1]+=val;
				lazy[2*ind+2]+=val;
			}
			return ;
		}
		int mid=(low+high)/2;
		update(2*ind+1,low,mid,l,r,val);
		update(2*ind+2,mid+1,high,l,r,val);
		st[ind]=min(st[2*ind+1],st[2*ind+2]); 
	}
public:
	int query(int ind,int low,int high,int l,int r){
		// upadtes if updates are remaining
		if(lazy[ind]!=0){
			st[ind]+=lazy[ind];
			if(low!=high){
				lazy[2*ind+1]+=lazy[ind];
				lazy[2*ind+2]+=lazy[ind];
			}
			lazy[ind]=0;
		}


		// no overlap 
		if(high<l || low>r) return INT_MAX;
		if(low>=l && high<=r) {
			return st[ind];
		}
		int mid=(low+high)/2;
		int left=query(2*ind+1,low,mid,l,r);
		int right=query(2*ind+2,mid+1,high,l,r);
		return min(left,right);
	}
};
void solve() {
    string s; cin >> s;
    for (int i = 0; i < s.size(); i++) {
        int best = s[i] - '0', pos = i;
        for (int j = i; j < min(i + 10, (int) s.size()); j++) {
            if (s[j] - '0' - (j - i) > best) {
                best = s[j] - '0' - (j - i);
                pos = j;
            }
        }
        while (pos > i) {
            swap(s[pos], s[pos - 1]);
            pos--;
        }
        s[i] = char(best + '0');
    }
    cout << s<<"\n";
}
signed main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while(t--){
    	solve();
    }

	return 0;
}

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

using ll=long long;
using namespace std;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;

    while (t--) {
        string s;
        cin >> s;

        for (int i = 1; i<s.size(); ++i) {
            int n = s[i] - '0';
            int j;
            for (j = i-1; j>=0; --j) {
                if (n - i+j > s[j] - '0') {
                    s[j+1] ^= s[j];
                    s[j] ^= s[j+1];
                    s[j+1] ^= s[j];
                } else {
                    break;
                }
            }

            s[j+1] = n - i + j + 1 + '0';
        }

        cout << s << '\n';
    }

    return 0;
}