#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pr;
string s;
struct cmp//自定义优先级
{
bool operator()(const pr a,const pr b)
{
if(a.first!=b.first)
return a.first>b.first;
else
return a.second>b.second;
}
};
priority_queue<pr,vector<pr>,cmp>q;
int main()
{
int i,j,k,m,n;
int t;
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--)
{
// int minn=10;
while(!q.empty())
q.pop();
cin>>s;
for(i=0; i<s.size(); i++)
{
int a=s[i]-'0';
q.push({a,i});
}
int d=-1;
pr it;
m=s.size();//一开始忘记初始化,一直不对
n=m;
while(q.size())
{
it=q.top();
if(it.second>=m)
{
cout<<min(it.first,9);
q.pop();
continue;
}
if(it.second>d)
{
d=it.second;
cout<<it.first;
}
else
{
// cout<<it.first<<"++++++"<<endl;
q.push({it.first+1,n});
n++;
}
q.pop();
}
cout<<endl;
}
}
05-23
206
12-01
227