ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 202 ms):
for u in range(int(input())):
    s = input()
    ans = []
    for i in s:
        ans.append(int(i))
    i = 0
    while i < len(s):
        while i > 0 and ans[i] > ans[i - 1] + 1:
            temp = ans[i] - 1
            ans[i] = ans[i - 1]
            ans[i - 1] = temp
            i -= 1
        i += 1
    print(*ans, sep = "")

Solution 2 (runtime: 718 ms):
t=int(input())
for _ in range(t):
    s=input()
    l=list(map(int,s))
    for i in range(1,len(s)):
        while i>0 and l[i]>l[i-1]+1:
            l[i],l[i-1]=l[i-1],l[i]-1
            i-=1
    print(''.join(map(str,l)))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 202 ms):
for u in range(int(input())):
    s = input()
    ans = []
    for i in s:
        ans.append(int(i))
    i = 0
    while i < len(s):
        while i > 0 and ans[i] > ans[i - 1] + 1:
            temp = ans[i] - 1
            ans[i] = ans[i - 1]
            ans[i - 1] = temp
            i -= 1
        i += 1
    print(*ans, sep = "")

Solution 2 (runtime: 1202 ms):
t = int(input())



for _ in range(t):

    word = input()

    s = [int(digit) for digit in word]

    l = len(s)



    for i in range(l):

        findMax= s[i]

        maxPos = i

        for j in range(10):

            if s[i+j]>findMax+((j+i)-maxPos):

                findMax = s[i+j]

                maxPos = i+j

            

            if l-(i+j)-1==0:

                break



        for j in range(maxPos-i):

            temp = s[maxPos-1]

            s[maxPos-1] = s[maxPos]-1

            s[maxPos] = temp

            maxPos-=1



    print("".join([str(digit) for digit in s]))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 202 ms):
for u in range(int(input())):
    s = input()
    ans = []
    for i in s:
        ans.append(int(i))
    i = 0
    while i < len(s):
        while i > 0 and ans[i] > ans[i - 1] + 1:
            temp = ans[i] - 1
            ans[i] = ans[i - 1]
            ans[i - 1] = temp
            i -= 1
        i += 1
    print(*ans, sep = "")

Solution 2 (runtime: 203 ms):
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))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 202 ms):
for u in range(int(input())):
    s = input()
    ans = []
    for i in s:
        ans.append(int(i))
    i = 0
    while i < len(s):
        while i > 0 and ans[i] > ans[i - 1] + 1:
            temp = ans[i] - 1
            ans[i] = ans[i - 1]
            ans[i - 1] = temp
            i -= 1
        i += 1
    print(*ans, sep = "")

Solution 2 (runtime: 702 ms):
n = int(input())

res = []

for _ in range(n):

    s = input()

    temp = []

    for ch in s:

        temp.append(int(ch))

    for i in range(1, len(s)):

        j = i - 1

        while j >= 0:

            r = temp[j+1]

            l = temp[j]

            if r > l + 1:

                temp[j] = r - 1

                temp[j+1] = l

            else:

                break

            j -= 1

    r = ''

    for n in temp:

        r += str(n)

    res.append(r)



for val in res:

    print(val)
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 202 ms):
for u in range(int(input())):
    s = input()
    ans = []
    for i in s:
        ans.append(int(i))
    i = 0
    while i < len(s):
        while i > 0 and ans[i] > ans[i - 1] + 1:
            temp = ans[i] - 1
            ans[i] = ans[i - 1]
            ans[i - 1] = temp
            i -= 1
        i += 1
    print(*ans, sep = "")

Solution 2 (runtime: 218 ms):
for _ in range(int(input())):

    s=list(input())

    #print(s)

    for i in range(len(s)):

        val=str(s[i])

        index=i



        for j in range(i+1,min(i+10,len(s))):

            if (int(s[j])-(j-i))>int(val):

                val=str(int(s[j])-(j-i))

                index=j 

        

        if index!=i:

            prev=s[i]

            for j in range(i+1,index+1):

                x=s[j]

                s[j]=prev

                prev=x

                

            s[i]=val

    print("".join(s))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 202 ms):
for u in range(int(input())):
    s = input()
    ans = []
    for i in s:
        ans.append(int(i))
    i = 0
    while i < len(s):
        while i > 0 and ans[i] > ans[i - 1] + 1:
            temp = ans[i] - 1
            ans[i] = ans[i - 1]
            ans[i - 1] = temp
            i -= 1
        i += 1
    print(*ans, sep = "")

Solution 2 (runtime: 624 ms):
def solve():

    s = list(input().strip())  # Convert string to list for mutability

    n = len(s)



    for i in range(1, n):

        j, curr = i - 1, i

        while j >= 0 and s[curr] > '0' and s[curr] > chr(ord(s[j]) + 1):

            s[curr] = chr(ord(s[curr]) - 1)  # Decrease digit

            s[curr], s[j] = s[j], s[curr]  # Swap

            curr -= 1

            j = curr - 1



    print("".join(s))



# Handling multiple test cases

t = int(input())

for _ in range(t):

    solve()
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 202 ms):
for u in range(int(input())):
    s = input()
    ans = []
    for i in s:
        ans.append(int(i))
    i = 0
    while i < len(s):
        while i > 0 and ans[i] > ans[i - 1] + 1:
            temp = ans[i] - 1
            ans[i] = ans[i - 1]
            ans[i - 1] = temp
            i -= 1
        i += 1
    print(*ans, sep = "")

Solution 2 (runtime: 234 ms):
n = int(input())

for x in range(n):

s= list(map(int, input()))

g = len(s)

for i in range(1,g):

for j in range(0, s[i]):

if(i-j-1 < 0):

break

if(s[i-j]-1 > s[i-j-1]):

temp = s[i-j-1]

s[i-j-1] = s[i-j]-1

s[i-j] = temp

else:

break

result = ''.join(map(str,s))

print(result)
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 202 ms):
for u in range(int(input())):
    s = input()
    ans = []
    for i in s:
        ans.append(int(i))
    i = 0
    while i < len(s):
        while i > 0 and ans[i] > ans[i - 1] + 1:
            temp = ans[i] - 1
            ans[i] = ans[i - 1]
            ans[i - 1] = temp
            i -= 1
        i += 1
    print(*ans, sep = "")

Solution 2 (runtime: 156 ms):
for _ in range(int(input())):

a = input()

s = [int(digit) for digit in a]

n = len(s)

for i in range(n):

best_value = s[i]

best_idx = -1

for j in range(i + 1, min(i + 9, n)):

score = s[j]-(j - i)

if score>best_value:

best_value=score

best_idx=j



if best_idx != -1:

# print(best_value,s[best_idx],i,best_idx)

s[i], s[best_idx] = best_value, s[i]

for j in range(best_idx, i+1, -1):

s[j], s[j - 1] = s[j - 1], s[j]

# print(s)



print("".join(map(str, s)))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 202 ms):
for u in range(int(input())):
    s = input()
    ans = []
    for i in s:
        ans.append(int(i))
    i = 0
    while i < len(s):
        while i > 0 and ans[i] > ans[i - 1] + 1:
            temp = ans[i] - 1
            ans[i] = ans[i - 1]
            ans[i - 1] = temp
            i -= 1
        i += 1
    print(*ans, sep = "")

Solution 2 (runtime: 171 ms):
mod = 1e9 + 7

for _ in range(int(input())):

s = list(map(int,list(input())))

for i in range(len(s)-1):

mxi = -1

mx = 0

for j in range(1,10):

if i + j >= len(s):

break

if int(s[i+j]) - j - int(s[i]) > mx:

mx = int(s[i+j]) - j - int(s[i])

mxi = j

if mxi == -1:

continue



for jj in range(i+mxi,i,-1):

s[jj],s[jj-1] = s[jj-1],s[jj] - 1



print(''.join(list(map(str,s))))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 202 ms):
for u in range(int(input())):
    s = input()
    ans = []
    for i in s:
        ans.append(int(i))
    i = 0
    while i < len(s):
        while i > 0 and ans[i] > ans[i - 1] + 1:
            temp = ans[i] - 1
            ans[i] = ans[i - 1]
            ans[i - 1] = temp
            i -= 1
        i += 1
    print(*ans, sep = "")

Solution 2 (runtime: 218 ms):
t =  int(input())

def solve():

s = [int(i) for i in list(input())]

n = len(s)

for i in range(1,n,1):

for j in range(max(i-10, 0), i):

if s[i] - (i-j) > s[j]:

tmp = s[j:i]

s[j] = s[i] - (i-j)

s[j+1:i+1] = tmp

break

print("".join([str(i) for i in s]))

return

for i in range(t):

solve()
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 202 ms):
for u in range(int(input())):
    s = input()
    ans = []
    for i in s:
        ans.append(int(i))
    i = 0
    while i < len(s):
        while i > 0 and ans[i] > ans[i - 1] + 1:
            temp = ans[i] - 1
            ans[i] = ans[i - 1]
            ans[i - 1] = temp
            i -= 1
        i += 1
    print(*ans, sep = "")

Solution 2 (runtime: 906 ms):
def solve():

s = list(input())

n = len(s)

while True:

changed = False

for i in range(1, n):

if s[i] != '0' and int(s[i]) - 1 > int(s[i-1]):

num = int(s[i])

s[i] = str(int(s[i-1]))

s[i-1] = str(num - 1)

changed = True

if not changed:

break

print("".join(s))



t = int(input())

for _ in range(t):

solve()
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 202 ms):
for u in range(int(input())):
    s = input()
    ans = []
    for i in s:
        ans.append(int(i))
    i = 0
    while i < len(s):
        while i > 0 and ans[i] > ans[i - 1] + 1:
            temp = ans[i] - 1
            ans[i] = ans[i - 1]
            ans[i - 1] = temp
            i -= 1
        i += 1
    print(*ans, sep = "")

Solution 2 (runtime: 265 ms):
for _ in range(int(input())):

s = list(map(int,input()))

for i in range(9):

for j in range(len(s)-1):

if s[j] < s[j+1] - 1:

s[j],s[j+1] = s[j+1]-1,s[j]

print(*s,sep= '')
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 639 ms):
for _ in range(int(input())):
    a = list(map(int,list(input())))
    n = len(a)
    exists = True
    while exists:
        exists = False
        for index in range(0,n-1):
            if a[index]<a[index+1]-1:
                a[index],a[index+1] = a[index+1]-1,a[index]
                exists = True
    print(''.join(map(str,a)))

Solution 2 (runtime: 187 ms):
for _ in range(int(input())):
  s=list(map(int,input()[::-1]))
  a=[]
  while s:
    m=s[-1]
    x=-1
    for i in range(-1,max(-11,-len(s)-1),-1):
      if x-m==9:
        break
      if s[i]+i+1>m:
        m=s[i]+i+1
        x=i
    a.append(m)
    del s[x]
  print("".join(map(str,a)))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 639 ms):
for _ in range(int(input())):
    a = list(map(int,list(input())))
    n = len(a)
    exists = True
    while exists:
        exists = False
        for index in range(0,n-1):
            if a[index]<a[index+1]-1:
                a[index],a[index+1] = a[index+1]-1,a[index]
                exists = True
    print(''.join(map(str,a)))

Solution 2 (runtime: 233 ms):
import sys 
from math import*
from collections import*
I=lambda: map(int,input())
for i in range(int(input())):
    a=list(I())
    n=len(a)
    for j in range(n):
        for k in range(j,max(0,j-10,),-1):
            if a[k-1]+1<a[k]:
                a[k],a[k-1]=a[k-1],a[k]-1
                
    print(*a,sep="")
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 639 ms):
for _ in range(int(input())):
    a = list(map(int,list(input())))
    n = len(a)
    exists = True
    while exists:
        exists = False
        for index in range(0,n-1):
            if a[index]<a[index+1]-1:
                a[index],a[index+1] = a[index+1]-1,a[index]
                exists = True
    print(''.join(map(str,a)))

Solution 2 (runtime: 296 ms):
def fun(s):
    for i in range(1, len(s)):
        while i!=0 and s[i]-1 > s[i-1]:
            s[i], s[i-1] = s[i-1], s[i]-1
            i-=1
            
    return ''.join(map(str, s))
    
if __name__ == "__main__":
    for _ in range(int(input())):
        n=list(map(int, input()))
        rs=fun(n)
        print(rs)
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 639 ms):
for _ in range(int(input())):
    a = list(map(int,list(input())))
    n = len(a)
    exists = True
    while exists:
        exists = False
        for index in range(0,n-1):
            if a[index]<a[index+1]-1:
                a[index],a[index+1] = a[index+1]-1,a[index]
                exists = True
    print(''.join(map(str,a)))

Solution 2 (runtime: 249 ms):
for _ in range(int(input())):
    a = list(map(int, list(input())))
    for i in range(1, len(a)):
        for j in range(i, 0, -1):
            if a[j] - 1 > a[j - 1]:
                a[j], a[j - 1] = a[j - 1], a[j] - 1
            else:
                break
    print(*a, sep="")
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 639 ms):
for _ in range(int(input())):
    a = list(map(int,list(input())))
    n = len(a)
    exists = True
    while exists:
        exists = False
        for index in range(0,n-1):
            if a[index]<a[index+1]-1:
                a[index],a[index+1] = a[index+1]-1,a[index]
                exists = True
    print(''.join(map(str,a)))

Solution 2 (runtime: 750 ms):
for _ in range(int(input())):
    a=list(input())
    for i in range(len(a)):
        a[i]=int(a[i])
    for i in range(9):
        for j in range(len(a)-1):
            if a[j]<(a[j+1]-1):
                a[j],a[j+1]=a[j+1]-1,a[j]
    print(*a,sep='')
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 639 ms):
for _ in range(int(input())):
    a = list(map(int,list(input())))
    n = len(a)
    exists = True
    while exists:
        exists = False
        for index in range(0,n-1):
            if a[index]<a[index+1]-1:
                a[index],a[index+1] = a[index+1]-1,a[index]
                exists = True
    print(''.join(map(str,a)))

Solution 2 (runtime: 1264 ms):
for _ in range(int(input())):
    s = list(map(int,input()))
    i = 1
    while i<len(s):
        if i > 0 and s[i] > s[i-1] + 1 :
            s[i],s[i-1] = s[i-1],s[i]-1
            i -= 1
        else:
            i += 1
    print(''.join(str(i) for i in s))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 639 ms):
for _ in range(int(input())):
    a = list(map(int,list(input())))
    n = len(a)
    exists = True
    while exists:
        exists = False
        for index in range(0,n-1):
            if a[index]<a[index+1]-1:
                a[index],a[index+1] = a[index+1]-1,a[index]
                exists = True
    print(''.join(map(str,a)))

Solution 2 (runtime: 202 ms):
t=int(input())
for _ in range(t):
  n=input()
  l=[]
  for i in n:
    l.append(int(i))
  for i in range(1,len(l)):
    j=i
    while j>=1 and l[j]-1>l[j-1]:
      l[j-1],l[j]=l[j]-1,l[j-1]
      j-=1
  print("".join(map(str,l)))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 639 ms):
for _ in range(int(input())):
    a = list(map(int,list(input())))
    n = len(a)
    exists = True
    while exists:
        exists = False
        for index in range(0,n-1):
            if a[index]<a[index+1]-1:
                a[index],a[index+1] = a[index+1]-1,a[index]
                exists = True
    print(''.join(map(str,a)))

Solution 2 (runtime: 858 ms):
def solution():
    a = list(map(int, list(input())))
    for i in range(len(a)):
        _, j = max((a[j]-(j-i), -j) for j in range(i, min(i+9+1, len(a))))
        j = -j
        for k in reversed(range(i+1, j+1)):
            a[k-1], a[k] = a[k]-1, a[k-1]
    return "".join(map(str, a))

for _ in range(int(input())):
    print(solution())
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 639 ms):
for _ in range(int(input())):
    a = list(map(int,list(input())))
    n = len(a)
    exists = True
    while exists:
        exists = False
        for index in range(0,n-1):
            if a[index]<a[index+1]-1:
                a[index],a[index+1] = a[index+1]-1,a[index]
                exists = True
    print(''.join(map(str,a)))

Solution 2 (runtime: 296 ms):
def highest_var(x):
    while True:
        max_n = max(x)  
        check = False   
        while max_n > 1:
            for i in range(1, len(x)):  
                if x[i] == max_n and x[i - 1] < max_n - 1:
                    x[i - 1], x[i] = x[i] - 1, x[i - 1]  
                    check = True  
            max_n -= 1
        if not check:  
            break
    return x


t = int(input())
ab_res = []
for _ in range(t):
    s = input().strip()
    x = list(map(int, s))  
    x = highest_var(x)
    ab_res.append(''.join(map(str, x)))

print('\n'.join(ab_res))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 639 ms):
for _ in range(int(input())):
    a = list(map(int,list(input())))
    n = len(a)
    exists = True
    while exists:
        exists = False
        for index in range(0,n-1):
            if a[index]<a[index+1]-1:
                a[index],a[index+1] = a[index+1]-1,a[index]
                exists = True
    print(''.join(map(str,a)))

Solution 2 (runtime: 218 ms):
import sys
input = sys.stdin.readline
 
t = int(input())
for _ in range(t):
    s = list(input().strip())
    n = len(s)
 
    i = n - 1
    while i > 0:
        while True:
            if s[i] > '0' and ord(s[i]) - ord(s[i - 1]) > 1:
                s[i] = chr(ord(s[i]) - 1)
                s[i], s[i - 1] = s[i - 1], s[i]
                if i < n - 1:
                    i += 1
            else:
                break
        i -= 1
    print(''.join(s))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 639 ms):
for _ in range(int(input())):
    a = list(map(int,list(input())))
    n = len(a)
    exists = True
    while exists:
        exists = False
        for index in range(0,n-1):
            if a[index]<a[index+1]-1:
                a[index],a[index+1] = a[index+1]-1,a[index]
                exists = True
    print(''.join(map(str,a)))

Solution 2 (runtime: 203 ms):

import sys

#input=sys.stdin.readline

def solve():
    s = input()
    n = len(s)
    l = [int(c) for c in s]
    for i in range(n):
        best = l[i]
        id = i
        j = i+1
        while(j<i+10 and j<n):
            if ( l[j] - (j-i) > best):
                id = j 
                best = l[j] - (j-i)
            j+=1
        while(id>i):
            l[id],l[id-1] = l[id-1],l[id]-1
            id-=1
        l[i] = str(l[i])
    
    sol = ''.join(l)
    print(sol)
    

t = int(input())
for _ in range(t):
    solve()
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 639 ms):
for _ in range(int(input())):
    a = list(map(int,list(input())))
    n = len(a)
    exists = True
    while exists:
        exists = False
        for index in range(0,n-1):
            if a[index]<a[index+1]-1:
                a[index],a[index+1] = a[index+1]-1,a[index]
                exists = True
    print(''.join(map(str,a)))

Solution 2 (runtime: 140 ms):
import sys

input = sys.stdin.readline
write = sys.stdout.write


def solve():
    # make left as big as possible
    # if curr > left + 1
    # always swap, repeatedly too
    s = [int(x) for x in input().strip()]
    for i in range(1, len(s)):
        for j in range(i, 0, -1):  # at most ~9 iterations
            if not (s[j - 1] < s[j] - 1):
                break
            s[j - 1], s[j] = s[j] - 1, s[j - 1]

    write("".join(map(str, s)) + "\n")


if __name__ == "__main__":
    t = int(input())
    for i in range(t):
        solve()
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 639 ms):
for _ in range(int(input())):
    a = list(map(int,list(input())))
    n = len(a)
    exists = True
    while exists:
        exists = False
        for index in range(0,n-1):
            if a[index]<a[index+1]-1:
                a[index],a[index+1] = a[index+1]-1,a[index]
                exists = True
    print(''.join(map(str,a)))

Solution 2 (runtime: 734 ms):
def lists(L, X):
    for i in range(len(L)):
        max1 = int(L[i])
        index = i
        for j in range(i, min(i + 10, len(L))):
            if int(L[j]) - (j - i) > max1:
                max1 = int(L[j]) - (j - i)
                index = j
        while index > i:
            L[index], L[index - 1] = L[index - 1], L[index]
            index -= 1
        X.append(max1)

n = int(input())
for _ in range(n):
    L = [int(j) for j in input().strip()]
    X = []
    lists(L, X)
    y = ''.join(map(str, X))
    print(y)
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 639 ms):
for _ in range(int(input())):
    a = list(map(int,list(input())))
    n = len(a)
    exists = True
    while exists:
        exists = False
        for index in range(0,n-1):
            if a[index]<a[index+1]-1:
                a[index],a[index+1] = a[index+1]-1,a[index]
                exists = True
    print(''.join(map(str,a)))

Solution 2 (runtime: 515 ms):

def solve(s):
	if type(s) is str: s = [*map(int,iter(s))]
	s.reverse()
	i = len(s)-1
	o = []
	while i >= 0:
		b = 0
		for j in range(1,min(i+1,10)):
			if s[i-j] - j > s[i-b] - b:
				b = j
		o.append(s[i-b]-b)
		del s[i-b]
		i -= 1
	return o

for _ in range(int(input())):
	print("".join(map(str,solve(input()))))
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 639 ms):
for _ in range(int(input())):
    a = list(map(int,list(input())))
    n = len(a)
    exists = True
    while exists:
        exists = False
        for index in range(0,n-1):
            if a[index]<a[index+1]-1:
                a[index],a[index+1] = a[index+1]-1,a[index]
                exists = True
    print(''.join(map(str,a)))

Solution 2 (runtime: 187 ms):

t=int(input())
for _ in range(t):
    s =[int(x) for x in list(input())]
    n=len(s)
    for i in range(1,n):
        if s[i] !=0 and s[i] !=1:
            for j in range(i-1,-1,-1):
                if s[j]<s[j+1]-1:
                    temp=s[j+1]-1
                    s[j+1]=s[j]
                    s[j]=temp
                else:
                    break
        else:
            continue
    for x in s:
        print(x, end="")
    print()
Problem: 2050D - Digital string maximization
Language: python

Solution 1 (runtime: 639 ms):
for _ in range(int(input())):
    a = list(map(int,list(input())))
    n = len(a)
    exists = True
    while exists:
        exists = False
        for index in range(0,n-1):
            if a[index]<a[index+1]-1:
                a[index],a[index+1] = a[index+1]-1,a[index]
                exists = True
    print(''.join(map(str,a)))

Solution 2 (runtime: 218 ms):
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()