#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Mod=998244353;

void solve() {

    string s;
    cin >> s;

    for(int i=0;i<s.size();++i){
        int best =s[i]-'0';
        int k=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;
                k=j;
            }
        }
         while(k>i){
            swap(s[k],s[k--]);
         }
         s[i]=char(best+'0');
    }
    cout << s << '\n';
}

int main(){ 
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	
    int t;
    cin >> t;
    while (t--) solve();
    

    return 0;
}
