ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: c++17 

Code 1:
#include <bits/stdc++.h>

using namespace std;

int find(string &s, int r)
{
    int l = r;
    while (l >= 0)
    {
        if (s[r] - s[l] > 1 || s[l] - s[r] > 1)
        {
            return l;
        }
        else
        {
            l--;
        }
    }
    return l;
}

void change(string &s, int r)
{
    int l = r;
    while (l < s.length() - 1)
    {
        if (s[l + 1] - s[l] > 1)
        {
            char temp = s[l + 1];
            s[l + 1] = s[l];
            s[l] = temp - 1;
            l++;
            // cout << s << " s from change" << endl;
        }
        else
        {
            return;
        }
    }
    return;
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        int r = s.size() - 1;
        while (r >= 0)
        {
            if (s[r] == '0')
            {
                r--;
            }
            else
            {
                int k;
                k = find(s, r);
                // cout << k << endl;
                if (r >= 0)
                {
                    change(s, k);
                }
                r = k;
                // cout << r << "next" << " st " << s << endl;
            }
        }
        cout << s << endl;
    }
    return 0;
}

Code 2:
#include <bits/stdc++.h>

using namespace std;

int find(string &s, int r)
{
    int l = r-1;
    // cout << l << endl;
    while (l >= 0)
    {
        if (s[r] - s[l] > 1 || s[l] - s[r] > 1)
        {
            return l;
        }
        else
        {
            l--;
            r--;
        }
    }
    return l;
}

void change(string &s, int r)
{
    int l = r;
    while (l < s.length() - 1)
    {
        if (s[l + 1] - s[l] > 1)
        {
            char temp = s[l + 1];
            s[l + 1] = s[l];
            s[l] = temp - 1;
            l++;
            // cout << s << " s from change" << endl;
        }
        else
        {
            return;
        }
    }
    return;
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        int r = s.size() - 1;
        while (r >= 0)
        {
            if (s[r] == '0')
            {
                r--;
            }
            else
            {
                int k;
                k = find(s, r);
                // cout << k << endl;
                if (k >= 0)
                {
                    change(s, k);
                }
                r = k;
                // cout << r << "next" << " st " << s << endl;
            }
        }
        cout << s << endl;
    }
    return 0;
}

Answer: 2
Problem: 2050D - Digital string maximization
Language: c++20 

Code 1:
#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 int long long

typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

signed main(){

int t;

cin>>t;

while(t--){

string n;

cin>>n;

vector<char>a;

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

a.push_back(n[i]);

}

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

//     cout<<a[i]<<' ';

// }

// cout<<endl;

// reverse(a.begin(),a.end());

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

int y=i;

int x=i;

while(((a[i])>(a[x-1]+('1'-'0')))&&(x>0)){

a[i]-=('1'-'0');

//cout<<a[i]<<' '<<a[x-1]<<endl;

swap(a[i],a[x-1]);

x--;

i--;

}

y=i;

}

// for(int i=0;i<)

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

cout<<a[i];

}

cout<<endl;

}

}

Code 2:
#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 int long long

typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

// bool comp(int &a,int&b){

//     if(a>b+1){

//         a--;

//         return a>b;

//     }

// }

signed main(){

int t;

cin>>t;

while(t--){

int n;

cin>>n;

int x=n;

vector<int>a;

if(x==0){

cout<<0<<endl;

}

else{

while(x!=0){

a.push_back(x%10);

x/=10;

}

reverse(a.begin(),a.end());

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

int y=i;

int x=i;

while((a[i]>a[x-1]+1)&&(x>0)){

a[i]--;

//cout<<a[i]<<' '<<a[x-1]<<endl;

swap(a[i],a[x-1]);

x--;

i--;

}

y=i;

}

// for(int i=0;i<)

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

cout<<a[i];

}

cout<<endl;

}

}

}

Answer: 1
Problem: 2050D - Digital string maximization
Language: python

Code 1:
t = int(input())
for _ in range(t):
    num = list(input())  # Convert string to list for mutable operations
    n = len(num)
    for i in range(n - 1):
        j = i + 1
        while j < n and (int(num[j]) - 1 > int(num[j - 1])):
            temp = str(int(num[j]) - 1)
            num[j] = num[j - 1]
            num[j - 1] = temp
            j -= 1  # Move backward to recheck the order
            if j <= 0:  # Prevent going out of bounds
                break
    print(''.join(num))  # Convert list back to string for output


Code 2:
t = int(input())
for _ in range(t):
    num = input()
    n = len(num)
    ans = ""
    for j in range(n-1):
        max_el = j
        for i in range(j+1, n):
            # print(num)
            # print(f"i: {i}, j: {j}")
            if(int(num[i]) == 0): continue
            if((int(num[i]) - (i - j)) > int(num[max_el]) - (max_el - j)):
                max_el = i
        if(max_el != j):
            num = num[:j]+str(int(num[max_el]) - (max_el - j))+num[j:]
            # print(f"num: {num}")
            num = num[:max_el+1] + num[max_el+2:]
    print(num)

Answer: 1
Problem: 2050D - Digital string maximization
Language: java

Code 1:
import java.math.*;

import java.util.*;



public class Main {

static int N = (int)2e5 + 5;

static int[] a = new int[N];

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int T = sc.nextInt();

while(T-- > 0){

String s = sc.next();

int len = s.length();

for(int i = 1;i <= len;i++){

a[i] = (int)s.charAt(i - 1) - (int)'0';

}

for(int i = 1;i <= len;i++){

int x = a[i], idx = i;

int mx = x, id = -1;

for(int j = i + 1;j <= len && j <= i + 8;j++){

if(a[j] - (j - i) > mx){

mx = a[j] - (j - i);

idx = j;

}

}

for(int j = idx - 1;j >= i;j--){

int t = a[j];

a[j] = a[j + 1] - 1;

a[j + 1] = t;

}

}

for(int i = 1;i <= len;i++){

System.out.print(a[i]);

}

System.out.println();

}

sc.close();

}

}

Code 2:
import java.math.*;

import java.util.*;



public class Main {

static int N = (int)2e5 + 5;

static int[] a = new int[N];

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int T = sc.nextInt();

while(T-- > 0){

String s = sc.next();

int len = s.length();

for(int i = 1;i <= len;i++){

a[i] = (int)s.charAt(i - 1) - (int)'0';

}

for(int i = 1;i <= len;i++){

int x = a[i], idx = i;

int mx = 0, id = -1;

for(int j = i + 1;j <= len && j <= i + 8;j++){

if(a[j] - (j - i) > mx){

mx = a[j] - (j - i);

idx = j;

}

}

for(int j = idx - 1;j >= i;j--){

int t = a[j];

a[j] = a[j + 1] - 1;

a[j + 1] = t;

}

}

for(int i = 1;i <= len;i++){

System.out.print(a[i]);

}

System.out.println();

}

sc.close();

}

}

Answer: 1
Problem: 2050D - Digital string maximization
Language: c++20 

Code 1:
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define pb push_back
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define alias cout << "Alias" << endl;
#define bob cout << "Bob" << endl;
const int MOD = 1e9+7;
const int INF = 1e18;

void solve() {
    string s; cin>>s;
    int n=s.size();
    vi arr;
    vi ans;
    int c=0;
    for(int i=0;i<min(10LL,n);i++){
        // cout << s[c+i] << " " << s[c+i]-'0'-i << endl;
        arr.pb(s[c+i]-'0'-i);
    }
    int val=*max_element(arr.begin(),arr.end());
    while(!arr.empty()){
        ans.pb(val);
        int i=0;
        vi temp;
        while(arr[i] != val){
            temp.pb(arr[i]);
            i++;
        }
        i++;
        while(i<arr.size()){
            temp.pb(arr[i]+1);
            i++;
        }
        arr.clear();
        if(c+10 < n){
            temp.pb(s[c+10]-'0'-9);
            c++;
        }
        arr = temp;
        if(!arr.empty()) val = *max_element(arr.begin(),arr.end());
    }
    for(auto ele: ans) cout << ele << "";
    cout << endl;
}

int32_t main() {
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Code 2:
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define pb push_back
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define alias cout << "Alias" << endl;
#define bob cout << "Bob" << endl;
const int MOD = 1e9+7;
const int INF = 1e18;

void solve() {
    string s; cin>>s;
    int n=s.size();
    vi arr;
    vi ans;
    int c=0;
    for(int i=0;i<min(10LL,n);i++){
        // cout << s[c+i] << " " << s[c+i]-'0'-i << endl;
        arr.pb(s[c+i]-'0'-i);
    }
    int val=*max_element(arr.begin(),arr.end());
    while(!arr.empty()){
        ans.pb(val);
        int i=0;
        vi temp;
        while(arr[i] != val){
            temp.pb(arr[i]);
            i++;
        }
        i++;
        while(i<arr.size()){
            temp.pb(arr[i]+1);
            i++;
        }
        arr.clear();
        if(c+10 < n){
            temp.pb(s[c+10]-9);
            c++;
        }
        arr = temp;
        if(!arr.empty()) val = *max_element(arr.begin(),arr.end());
    }
    for(auto ele: ans) cout << ele << "";
    cout << endl;
}

int32_t main() {
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


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

Code 1:
#include<bits/stdc++.h>
#define memclear(a) memset(a,0,sizeof(a))
using namespace std;
const int inf=0x3f3f3f3f;
using ll=long long;
int num[200050];
void solve(string s){
	int n=s.length();
	memclear(num);
	int i,j,maxn,maxi;
	for(i=0;i<n;i++){
		num[i]=s[i]-'0';
	}
	for(i=0;i<n;i++){
		maxn=num[i];
		maxi=i;
		for(int j=i+1;j<i+9&&j<=n;j++){
			int m=j-i;
			if(num[j]-m>maxn){
				maxn=num[j]-m;
				maxi=j;
			}
		}
		if(maxi!=i){
			for(int k=maxi;k>=i+1;k--){
				num[k]=num[k-1];
			}
			num[i]=maxn;
		}
	}
	for(int i=0;i<n;i++) cout<<num[i];
	cout<<"\n";
}
int main(){
  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  int t;
  cin>>t;
  while(t--){
		string s;
	  cin>>s;
	  solve(s);
	}
  return 0;
}


Code 2:
#include<bits/stdc++.h>
#define memclear(a) memset(a,0,sizeof(a))
using namespace std;
const int inf=0x3f3f3f3f;
using ll=long long;
int num[20050];
void solve(string s){
	int n=s.length();
	memclear(num);
	int i,j,maxn,maxi;
	for(i=0;i<n;i++){
		num[i]=s[i]-'0';
	}
	for(i=0;i<n;i++){
		maxn=num[i];
		maxi=i;
		for(int j=i+1;j<i+9&&j<=n;j++){
			int m=j-i;
			if(num[j]-m>maxn){
				maxn=num[j]-m;
				maxi=j;
			}
		}
		if(maxi!=i){
			for(int k=maxi;k>=i+1;k--){
				num[k]=num[k-1];
			}
			num[i]=maxn;
		}
	}
	for(int i=0;i<n;i++) cout<<num[i];
	cout<<"\n";
}
int main(){
  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  int t;
  cin>>t;
  while(t--){
		string s;
	  cin>>s;
	  solve(s);
	}
  return 0;
}


Answer: 1
Problem: 2050D - Digital string maximization
Language: c++20 

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;


void solution() {
    string s;cin>>s;
    int n=s.size();
    
    for(int i=0;i<n;i++){
        int maxi=(s[i]-'0'),ind=i;
        for(int j=0;j<=9;j++){
            if(i+j<n){
                if(s[i+j]-'0'-j>=maxi){
                    ind=i+j;
                    maxi=s[i+j]-'0';
                }
            }   
            else{
                break;
            }
        }
        char ch=s[ind]-(ind-i);
        for(int j=ind;j>i;j--){
            s[j]=s[j-1];
        }
        s[i]=ch;
    }

    cout<<s<<endl;


}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int Testcases = 1;
    cin >> Testcases;
    for (int i = 0; i < Testcases; i++) {
        solution();
    }
    return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;


void solution() {
    string s;cin>>s;
    int n=s.size();
    
    for(int i=0;i<n;i++){
        int maxi=(s[i]-'0'),ind=i;
        for(int j=1;j<=9;j++){
            if(i+j<n){
                if(s[i+j]-'0'-j>maxi){
                    ind=i+j;
                    maxi=s[i+j]-'0'-j;
                }
            }   
            else{
                break;
            }
        }
        // cout<<maxi<<endl;
        char ch=s[ind]-(ind-i);
        for(int j=ind;j>i;j--){
            s[j]=s[j-1];
        }
        s[i]=ch;
    }

    cout<<s<<endl;


}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int Testcases = 1;
    cin >> Testcases;
    for (int i = 0; i < Testcases; i++) {
        solution();
    }
    return 0;
}

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

Code 1:
#include <iostream>
#include <string>
using namespace std;

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        int posi = 0;
        while (s[posi] != '\0')
        {
            if (s[posi + 1] > s[posi] + 1)
            {
                char temp = s[posi];
                int tempo = s[posi + 1] - '0' - 1;
                s[posi] = tempo + '0';
                s[posi + 1] = temp;
                if (posi > 0)
                {
                    int positemp = posi;
                    while (s[positemp] > s[positemp - 1] + 1)
                    {
                        char temp2 = s[positemp - 1];
                        int tempo2 = s[positemp] - '0' - 1;
                        s[positemp - 1] = tempo2 + '0';
                        s[positemp] = temp2;
                        positemp--;
                        if (positemp <= 0)
                        {
                            // posi++;
                            break;
                        }
                    }
                }
            }
            posi++;
        }
        cout << s << endl;
    }
}

Code 2:
#include <iostream>
#include <string>
using namespace std;

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        int posi = 0;
        while (s[posi] != '\0')
        {
            if (s[posi + 1]>s[posi]+1 )
            {
                char temp = s[posi];
                int tempo = s[posi + 1] - '0' - 1;
                s[posi] = tempo + '0';
                s[posi + 1] = temp;
                posi = 0;
                continue;
            }
            posi++;
        }
        cout << s << endl;
    }
}

Answer: 1
Problem: 2050D - Digital string maximization
Language: python

Code 1:
for _ in range(int(input())):
    s = list(map(int, list(input())))
    n = len(s)
    

    for i in range(1, n):
        if s[i] == 0:
            continue
        for j in range(max(0, i - 9), i):
            if s[j] < s[i] - (i - j):
                new_head_value = s[i] - (i - j)
                idx = i - 1
                while idx != j - 1:
                    s[idx], s[idx + 1] = s[idx + 1], s[idx]
                    idx -= 1
                s[j] = new_head_value
                break


    for i in range(n):
        print(s[i], end='')
    print()

Code 2:
for _ in range(int(input())):
    s = list(map(int, list(input())))
    n = len(s)
    prev_max = s[0]
    prev_max_i = 0

    for i in range(1, n):
        if s[i] == 0:
            continue
        for j in range(prev_max_i, i):
            if s[j] + (i - j) >= 9:
                prev_max_i = j
                prev_max = s[j]
            if s[j] < s[i] - (i - j):
                temp = s[i]
                s.insert(j, s[i] - (i - j))
                s.pop(i + 1)
                # prev_max_i = j
                # prev_max = s[j]
                break

        # print(s)

    for i in range(n):
        print(s[i], end='')
    print()

Answer: 1
Problem: 2050D - Digital string maximization
Language: python

Code 1:
t= int(input())
for k in range(t):    
    a=list(input())
    b= len(a)
    for i in range(b):
        t= min(i+9,b)
        m= int(a[i])
        n=i
        for j in range(i,t):
            if (int(a[j])-j+i)> m:
                m= int(a[j])-j+i
                n= j
        while n>i:
            a[n],a[n-1]= a[n-1],str(int(a[n])-1)
            n-=1
    print("".join(a))

Code 2:
t= int(input())
for k in range(t):    
    a=input()
    b= len(a)
    for i in range(b):
        t= min(i+9,b)
        m= int(a[i])
        n=i
        for j in range(i,t):
            if (int(a[j])-j+i)> m:
                m= int(a[j])-j+i
                n= j
        a= a[0:i]+str(m)+a[i:n]+a[n+1:b]
    print(a)

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

Code 1:
#include<bits/stdc++.h>

  

using namespace std;

using ll = long long;

using ld = long double;

#define mod 998244353





void solve(){

    //code here

    string s; 

    cin>>s;

    vector<pair<int, int>> v;

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

        int t = s[i]-'0';

        v.push_back({t-i, i});

    }

    sort(v.begin(), v.end(), [&](auto a, auto b) {

        if(a.first == b.first) return a.second>b.second;

        return a.first>b.first;

    });

    

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

        if(v[i].second<= i) {

            cout<<v[i].first + v[i].second;

        } else {

            cout<<v[i].first + i;

        }

    }

    

    

    return ;

}

 

int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);



    // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    ll t = 1;

    cin >> t;

 

    while (t--){

        // cout<<"-----------"<<endl;

        solve();

        cout<<"\n";

    }

 

    return 0;

}

Code 2:
#include<bits/stdc++.h>

  

using namespace std;

using ll = long long;

using ld = long double;

#define mod 998244353





void solve(){

    //code here

    string s; cin >> s;

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

        int tmp = s[i] - '0', pos = i;

        for (int j = i; j < min(i + 10, (int) s.size()); j++) {

            if (s[j] - '0' - (j - i) > tmp) {

                tmp = s[j] - '0' - (j - i);

                pos = j;

            }

        }

        while (pos > i) {

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

            pos--;

        }

        s[i] = char(tmp + '0');

    }

    cout << s;



    

    

    return ;

}

 

int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);



    // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    ll t = 1;

    cin >> t;

 

    while (t--){

        // cout<<"-----------"<<endl;

        solve();

        cout<<"\n";

    }

 

    return 0;

}

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

Code 1:
#include <bits/stdc++.h>

using namespace std;



int32_t main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);

int tc;

cin>>tc;

string s;

while(tc--){

cin>>s;

string a = "";

int mx, itr;

while(s.size()) {

mx = -1;

for (int i = 0; i < 10; i++) {

if ((s[i]-'0')-i>mx) {

mx = (s[i]-'0') - i;

itr = i;

}

}

a = a + to_string(mx);

s.erase(s.begin()+ itr);

}

cout<<a<<'\n';

}

return 0;

}



Code 2:
#include <bits/stdc++.h>

using namespace std;



int32_t main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);

int tc;

cin>>tc;

string s;

while(tc--){

cin>>s;

int a;

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

for (int j = i; j >0 ; j--) {

if (s[j]-1>s[j-1]) {

a = s[j]-1;

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

s[j-1] = a;

}else break;

}

}

cout<<s<<'\n';

}

return 0;

}



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

Code 1:
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while (t--) {
        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';
    }

    return 0;
}


Code 2:
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        string ans;
        int cnt=0;
        while(ans.size()!=s.size()){
            int maxi=0;
            int index;
        for(int i=cnt;i<s.size();++i){
            if((s[i]-'0')-(i-cnt)>maxi){
                maxi=((s[i]-'0')-(i-cnt));
                index=i;
            }
        }
        while(index>cnt){
            swap(s[index],s[index-1]);
            index--;
        }
        ans=ans+to_string(maxi);
        cnt++;
        }
        cout<<ans<<endl;
    }
}

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

Code 1:
//trying :-}





//      (????????????
//       ~  ?? ~





#include <iostream>

#include <string>

#include <vector>

#include <set>

#include <unordered_set>

#include <algorithm>

#include <numeric>

#include <cmath>

#include <map>

using namespace std;

using ll = long long;



#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

#define f(i, a, b) for (int i = a; i < b; ++i)

#define pb push_back





void solve() {

string s;

cin>>s;

int n=s.length();

vector<int> a(n);

f(i,0,n) a[i]=s[i]-'0';



f(i,0,n){

int k=i;

f(j,i,n){

if(a[k]-k<a[j]-j){

k=j;

}

}

while(k>i){

a[k]-=1;

int t=a[k];

a[k]=a[k-1];

a[k-1]=t;

k--;

}

}

f(i,0,n) cout<<a[i];

cout<<"\n";





}



int main() {

fastio;

int t;

cin >> t;

while (t--) solve();



return 0;

}





//  :-

Code 2:
//trying :-}





//      (????????????
//       ~  ?? ~





#include <iostream>

#include <string>

#include <vector>

#include <set>

#include <unordered_set>

#include <algorithm>

#include <numeric>

#include <cmath>

#include <map>

using namespace std;

using ll = long long;



#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

#define f(i, a, b) for (int i = a; i < b; ++i)

#define pb push_back





void solve() {

string a;

cin>>a;

int n=a.size();







f(i,0,n){

int k=i;

f(j,i,min(n,i+10)){

if(a[k]-k<a[j]-j){

k=j;

}

}

while(k>i){

a[k]-=1;

char t=a[k];

a[k]=a[k-1];

a[k-1]=t;

k--;

}

}

f(i,0,n) cout<<a[i];

cout<<"\n";





}



int main() {

fastio;

int t;

cin >> t;

while (t--) solve();



return 0;

}





//  :-

Answer: 2