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

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;

void accelerate()
{
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}

void solve() {
    string n;
    cin >> n;
    char windows[9];
    int wSize = n.size() > 9 ? 9 : n.size();
    for (int i = 0; i < wSize; i++) {
        windows[i] = n[i];
    }
    char ans[n.size()+1];
    for (int i = 0; i < n.size(); i++) {
        int maxji = 0;
        int maxj = windows[0] - '0';
        for (int j = 1; j < wSize; j++) {
            int d = windows[j] - '0' - j;
            if (d > maxj) {
                maxj = d;
                maxji = j;
            }
        }
        ans[i] = '0' + maxj;
        for (int j = maxji+1; j < wSize; j++) {
            windows[j-1] = windows[j];
        }
        if (i + wSize < n.size()) {
            windows[wSize-1] = n[i+wSize];
        } else {
            wSize--;
        }
    }
    ans[n.size()] = '\0';
    cout << ans << endl;
}

signed main() {
    // accelerate();
    int tc = 1;
    cin >> tc;
    while (tc--) {
        solve();
    }
    return 0;
}


Solution 2 (runtime: 61 ms):
//// "و ذا النون اذ ذهب مغاضبا فظن ان لن نقدر عليه"

//// "فنادي في الظلمات ان لا اله لا انت سبحانك اني كنت من الظالمين"

////  "فاستجبنا له و نجينه من الغم و كذلك ننجي المؤمنين"

// MORE FALLS , HIGHER JUMPS YOU GET !! //

#include<iostream>

#include<vector>

#include<iomanip>

#include<queue>

#include <algorithm>

#include<climits>

#include <stack>

#define ll long long

#define ON(mask,bit) (mask | (1LL<<bit) )

#define OFF(mask,bit) ( mask & ~ ( 1LL << bit ) )

#define IsOn(mask,bit) (( mask>>bit) & 1LL)

#define toggle(mask,bit)( mask ^ (1LL<<bit) )

#define Isodd(mask) (mask & 1LL)

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>



/*

 ███████╗ █████╗ ████████╗███████╗███╗   ███╗ █████╗

 ██╔════╝██╔══██╗╚══██╔══╝██╔════╝████╗ ████║██╔══██╗

 █████╗  ███████║   ██║   █████╗  ██╔████╔██║███████║

 ██╔══╝  ██╔══██║   ██║   ██╔══╝  ██║╚██╔╝██║██╔══██║

 ██║     ██║  ██║   ██║   ███████╗██║ ╚═╝ ██║██║  ██║

 ╚═╝     ╚═╝  ╚═╝   ╚═╝   ╚══════╝╚═╝     ╚═╝╚═╝  ╚═╝

*/

void fast(){

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);

}

//       right left up  down

int dx []={ 1 , -1 , 0 ,  0  };

int dy []={ 0 ,  0 , 1 , -1  };



bool isPowerOfTwo(ll n) {

    return n > 0 && (n & (n - 1)) == 0;

}



vector<ll> Divisors(ll n){

// this one is for printing but same algo.

    vector <ll>v;

    for (ll i = 1; i*i <= n ; ++i) {

        if(n%i==0){

            v.push_back(i);

            if(n/i!=i){

                v.push_back(n/i);

            }

        }

    }

    return v;

}



vector<ll> PrimeFactors(ll n){

    // this part for printing too but same algo

    // take care each problem we change small things

  vector<ll>v;

    ll cntr=0;

    while (n%2==0){

        cntr++;

        n=n/2;

         /*v.push_back(i);*/

    }

    v.push_back(2);

    /*if(cntr)

        factors[2]=cntr;*/

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

        cntr=0;

        while (n%i==0){

            cntr++;

            n=n/i;

            // v.push_back(i);

        }

        /*if(cntr) {

            factors[i]=cntr; }*/

        v.push_back(i);

    }

    if(n>1){

        //v.push_back(n);

        //factors[n]=1;

        v.push_back(n);

    }

    return v;

}

/////////////////////// The code //////////////////////////



void elzhraa()

{



   string s;cin>>s;



    for (int i = 0; i < s.size(); ++i) {

        pair<int,int>p{s[i]-'0',i};// first ->data , second -> idx

        int j;

        for ( j = i+1; j <i+10 && j<s.size() ; ++j) {

            if(s[j]-'0'-(j-i)+1>p.first){

                p.first=s[j]-'0'-(j-i)+1;

                p.second=j;

            }

        }

        if(p.first!=s[i]-'0'+1&&p.second!=i){

            for (int k = p.second; k >i ; --k) {



                s[k]= s[k]-1;

                swap(s[k-1],s[k]);

            }

        }

    }

    cout<<s<<'\n';



}



int main() {



    /*freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);*/

    fast();

    int t =1;

    cin>>t;

    // seive(1e2);



    while (t--) {

        elzhraa();

    }



}