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

Solution 1 (runtime: 78 ms):
#include <bits/stdc++.h>
#define McQueen              \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define ll long long
#define pb push_back
#define true cout << "YES" << '\n'
#define false cout << "NO" << '\n'
#define none cout << "-1" << '\n'
using namespace std;
map<ll, ll> mp;
set<ll> st;
pair<ll, ll> p[210000];
vector<ll> v;
ll c[210000], a[210000];
bool bo[210000], b = 0;
ll n, m, t, k, cou, mx, x, y, res, ans, mn, sum, M = 1E9 + 7, MOD = M;
string s, r;
void solve()
{
    cin >> s;
    k = 0, mx = 0;

    for (int i = 0; i < s.size(); i++)
    {
        k = 0;
        for (int j = i; j <= min((ll)(s.size() - 1), (ll)(i + (9 - (s[i] - '0')))); j++)
        {
            if (((s[j] - '0') - k) >= 0)
                mx = max(((s[j] - '0') - k), mx);
            k++;
        }
        k = 0;
        // cout << mx << " ";
        for (int j = i; j <= min((ll)(s.size() - 1), (ll)(i + (9 - (s[i] - '0')))); j++)
        {
            if (((s[j] - '0') - k) == mx)
            {
                x = j;
                break;
            }
            k++;
        }
        for (int j = x; j > i; j--)
        {
            s[j] = s[j - 1];
        }
        s[i] = (mx + '0');
        //cout << s << '\n';
        mx = 0;
    }
    cout << s << '\n';
}

main()
{
    McQueen
            cin >>
        t;
    // t = 1;
    while (t--)
    {
        solve();
    }
}

Solution 2 (runtime: 78 ms):
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define MOD 1000000007
#define PI 3.141592653589793238462

typedef long long ll;

const int inf = 0x3f3f3f3f;
const int maxn = 2e6 + 6;
const double eps = 1e-8;
const int mod = 998244353;
const int N = 1e5 + 7;

// typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// ll powerFun(ll x, ll p) { ll res = 1; for (int i = 1; i <= p; i++) { res *= x; } return res; }
// ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); }
// bool isPrime(ll n) { if (n <= 1) return false; if (n <= 3) 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; }
// vector<ll> prime; void sieve_of_eratosthenes(ll n) { vector<bool> is_prime(n + 1, true); is_prime[0] = is_prime[1] = false; for (ll p = 2; p * p <= n; p++) { if (is_prime[p]) { for (ll i = p * p; i <= n; i += p) { is_prime[i] = false; } } } for (ll i = 2; i <= n; i++) { if (is_prime[i]) { prime.pb(i); } } }

void execute() {
    string s;cin>>s;
    string ans=s;
    int h=s.size();
    for(int i=0;i<h;i++){
        ll ele=s[i]-'0',maxi=ele,pos=-1;
        for(int j=i+1;j<min(13+i,h);j++){
            ll t=(s[j]-'0')+(i)-j;
            if(maxi<t){
                pos=j;
                maxi=t;
            }
        }
        if(pos!=-1){
            for(int k=pos;k>=i+1;k--){
                swap(s[k],s[k-1]);
            }
            s[i]=maxi+'0';
        }
    }
    cout<<s<<endl;
}

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

    ll Testcases;
    cin >> Testcases;

    while (Testcases--) {
        execute();
    }

    return 0;
}