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

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



using namespace std;



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;

}



int main() {

    int TESTS = 1; cin >> TESTS;

    while (TESTS --> 0) {

        solve();

        cout << '\n';

    }

    return 0;

}

Solution 2 (runtime: 77 ms):
/******************************************************************************



Online C++ Compiler.

Code, Compile, Run and Debug C++ program online.

Write your code in this editor and press "Run" button to compile and execute it.



*******************************************************************************/



#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp> // Common file

#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;

using namespace __gnu_pbds;



typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

typedef vector<int> vi;

typedef vector<ll> vll;

typedef pair<int, int> pi;

typedef pair<ll, ll> pll;

typedef pair<char,char> pch;



typedef tree<

ll,

null_type,

less<ll>,

rb_tree_tag,

tree_order_statistics_node_update>

ordered_set;



#define pb push_back

#define mp make_pair

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

#define prec(n) fixed << setprecision(n)

#define bit(n, i) ((n >> i) & 1)

#define maxArr(a, n) *max_element(a, a + n)

#define minArr(a, n) *min_element(a, a + n)

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

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

void display(bool answer) {

	cout << ((answer) ? "YES" : "NO");

}

#define pY { cout << "YES" << endl; return; }

#define pN { cout << "NO" << endl; return; }

#define minus1 {cout<<-1<<endl;return;}

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

inline ll lcm(ll a, ll b) {

	return (a * b) / __gcd(a, b);

}

inline int intlcm(int a, int b) {

	return (a * b) / __gcd(a, b);

}

inline int intpow(int a, int b) {

	return (int)(pow(a, b) + 0.5);

}

inline ll llpow(ll a, ll b) {

	return (ll)(pow(a, b) + 0.5);

}

inline void show(vll a) {

	for (auto it : a) {

		cout << it << " ";

	}

	cout << endl;

}



#define PI 3.14159265

const ll mod = 1000000007;

const ll mod2 = 998244353;

const ll mod3 = 1e9 +9;

const ll maxn = 1e6;

const ll inf = 1e17;

#define INF 0x3f3f3f3f



ll power(ll x, ll y,ll M) {

	ll temp;

	if (y == 0) return 1ll;

	temp = (power(x, y / 2, M)) % M;

	if (y % 2 == 0) return (temp * temp) % M;

	else return (((x % M) * temp) % M * temp) % M;

}



#define MAXN 1002

ll spf[MAXN];



void sieve() {

	for (ll i = 1; i < MAXN; i++) spf[i] = i;

	for (ll i = 2; i * i < MAXN; i++) {

		if (spf[i] == i) {

			for (ll j = i * i; j < MAXN; j += i) if (spf[j] == j) spf[j] = i;

		}

	}

}





ll maxSubArraySum(vll a) {

	ll size = a.size();

	ll max_so_far = INT_MIN, max_ending_here = 0;

	for (ll i = 0; i < size; i++) {

		max_ending_here = max_ending_here + a[i];

		if (max_so_far < max_ending_here) max_so_far = max_ending_here;

		if (max_ending_here < 0) max_ending_here = 0;

	}

	return max_so_far;

}







void solve() {

string s;

cin>>s;

ll n= s.length();

string ans="";

rep(i,0,n){

ll mx= s[i]-'0',pos = i;

for(ll j=1;j<11 and i+j<n;j++){

ll nm = s[i+j]-'0';

nm -= j;

if(nm > mx){

mx = nm;

pos=i+j;

}

}

// s[pos] = mx+'0';

// ans += mx+'0';

// cout<<mx<<" "<<pos<<endl;

for(ll j=pos;j>i;j--){

s[j]= s[j-1];

}

s[i]= mx+'0';

// cout<<s<<endl;

// swap(s[i],s[pos]);



}

cout<<s<<endl;

}

int main() {

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	cout.tie(0);

	ll t = 1;

	// SieveOfEratosthenes(maxn);

//	sieve();

	cin >> t;

	rep(i, 1, t + 1) {

		solve();

		// cout<<i<<endl;

	}



	return 0;

}