using System;
using System.Collections.Generic;
using System.Linq;
public class Program {
    public static void Main() {
        int t = int.Parse(Console.ReadLine());
        for (int _ = 0; _ < t; _++) {
            string s = Console.ReadLine();
            char[] arr = s.ToCharArray();
            int n = arr.Length;

            for (int i = 0; i < n; i++) {
                int bestValue = arr[i] - '0';
                int bestIndex = -1;

                // 只看右边最多 10 个字符(移动超过9步没有意义)
                int end = Math.Min(n - 1, i + 9);
                for (int j = i + 1; j <= end; j++) {
                    if (arr[j] == '0') continue;

                    int valueAfterMove = (arr[j] - '0') - (j - i);
                    if (valueAfterMove > bestValue) {
                        bestValue = valueAfterMove;
                        bestIndex = j;
                    }
                }

                if (bestIndex != -1) {
                    // 把 bestIndex 的字符移动到 i
                    // 先保存 bestIndex 的字符
                    char movedChar = arr[bestIndex];
                    // 把它移动到 i,其他的字符右移
                    for (int k = bestIndex; k > i; k--) {
                        arr[k] = arr[k - 1];
                    }
                    arr[i] = (char)('0' + bestValue);
                    //不需要更新 movedChar,因为 bestValue 已经是移动后的值
                }
            }

            Console.WriteLine(new string(arr));
        }
    }
}