ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;

#define int long long 

void dfs(unordered_map<int, vector<int>>& adj, int index, int p, vector<int>& parent, vector<int>& c_count)
{
    int count = 0;

    for(int i:adj[index])
    {
        if(i!=p)
        {
            parent[i] = index;
            count++;
            dfs(adj, i, index, parent, c_count);
        }
    }

    c_count[index] = count;
}

signed main()
{
    int tt;
    cin>>tt;

    while(tt--)
    {
        int n;
        cin>>n;

        unordered_map<int, vector<int>> adj;

        for(int i=0; i<n-1; i++)
        {
            int u, v;
            cin>>u>>v;

            u--;
            v--;

            adj[u].push_back(v);
            adj[v].push_back(u);
        }

        vector<int> parent(n, -1);
        vector<int> c_count(n, 0);

        dfs(adj, 0, -1, parent, c_count);
        set<pair<int, int>> st;

        for(int i=0; i<n; i++)st.insert({c_count[i], i});

        int ans = 0;
        int f = (*st.rbegin()).second;
        ans+=c_count[f];
        st.erase(*st.rbegin());

        if(f!=0)
        {
            auto record = st.find({c_count[parent[f]], parent[f]});
            if(record != st.end())st.erase(record);
            c_count[parent[f]]--;
            st.insert({c_count[parent[f]], parent[f]});
        }


        int f1 = (*st.rbegin()).second;
        ans+=c_count[f1];
        st.erase(*st.rbegin());

        if(st.empty())
        {
            cout<<0<<endl;
            continue;
        }

        cout<<ans<<endl;
    }

    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;

#define int long long 

signed main()
{
    int tt;
    cin>>tt;

    while(tt--)
    {
        int n;
        cin>>n;

        unordered_map<int, vector<int>> adj;
        vector<int> deg(n);

        for(int i=0; i<n-1; i++)
        {
            int u, v;
            cin>>u>>v;

            u--; v--;
            
            adj[u].push_back(v);
            adj[v].push_back(u);

            deg[u]++;
            deg[v]++;
        }

        set<pair<int, int>> st;
        int ans = 0;

        for(int i=0; i<n; i++)
        {
            st.erase({deg[i], i});

            for(int v:adj[i])
            {
                st.erase({deg[v], v});
                deg[v]--;
                st.insert({deg[v], v});
            }

            int temp = deg[i]-1;
            temp+=(*st.rbegin()).first;
            ans = max(ans, temp);

            for(int v:adj[i])
            {
                st.erase({deg[v], v});
                deg[v]++;
                st.insert({deg[v], v});
            }
        }

        cout<<ans<<endl;
    }

    return 0;
}
Problem: 2049B - pspspsps
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>



using namespace std;



void solve()

{

    int n;

    cin>>n;

    deque<char> dq;

    char c;

    for(int i=1;i<=n;i++)

    {

        cin>>c;

        dq.push_back(c);

    }

    while(!dq.empty() && dq.front()=='s')

    {

        dq.pop_front();

    }

    while(!dq.empty() && dq.back()=='p')

    {

        dq.pop_back();

    }

    int np=0,ns=0;

    for(auto c:dq)

    {

        if(c=='p')

        {

            np++;

        }

        else

        {

            ns++;

        }

    }

    if(np==0 || ns==0)

    {

        cout<<"YES"<<endl;

    }

    else

    {

        cout<<"NO"<<endl;

    }

}



int main()

{

    int t=1;

    cin>>t;

    while(t--)

    {

        solve();

    }

}
Problem: 2049B - pspspsps
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>



using namespace std;



void solve()

{

    int n;

    cin>>n;

    deque<char> dq;

    char c;

    for(int i=1;i<=n;i++)

    {

        cin>>c;

        dq.push_back(c);

    }

    while(!dq.empty() && dq.front()=='s')

    {

        dq.pop_front();

    }

    while(!dq.empty() && dq.back()=='p')

    {

        dq.pop_back();

    }

    int np=0,ns=0;

    for(auto c:dq)

    {

        if(c=='p')

        {

            np++;

        }

        else if(c=='s')

        {

            ns++;

        }

    }

    if(np==0 || ns==0)

    {

        cout<<"YES"<<endl;

    }

    else

    {

        cout<<"NO"<<endl;

    }

}



int main()

{

    int t=1;

    cin>>t;

    while(t--)

    {

        solve();

    }

}



Submission (verdict: Accepted):
#include<bits/stdc++.h>



using namespace std;



void solve()

{

    int n;

    cin>>n;

    deque<char> dq;

    char c;

    for(int i=1;i<=n;i++)

    {

        cin>>c;

        dq.push_back(c);

    }

    if(dq.size() && dq.front()=='s')

    {

        dq.pop_front();

    }

    if(dq.size() && dq.back()=='p')

    {

        dq.pop_back();

    }

    int np=0,ns=0;

    for(auto c:dq)

    {

        if(c=='p')

        {

            np++;

        }

        else if(c=='s')

        {

            ns++;

        }

    }

    if(np==0 || ns==0)

    {

        cout<<"YES"<<endl;

    }

    else

    {

        cout<<"NO"<<endl;

    }

}



int main()

{

    int t=1;

    cin>>t;

    while(t--)

    {

        solve();

    }

}
Problem: 2049B - pspspsps
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>



using namespace std;



void solve()

{

    int n;

    cin>>n;

    deque<char> dq;

    char c;

    for(int i=1;i<=n;i++)

    {

        cin>>c;

        dq.push_back(c);

    }

    while(!dq.empty() && dq.front()=='s')

    {

        dq.pop_front();

    }

    while(!dq.empty() && dq.back()=='p')

    {

        dq.pop_back();

    }

    int np=0,ns=0;

    for(auto c:dq)

    {

        if(c=='p')

        {

            np++;

        }

        else

        {

            ns++;

        }

    }

    if(np==0 || ns==0)

    {

        cout<<"YES"<<endl;

    }

    else

    {

        cout<<"NO"<<endl;

    }

}



int main()

{

    int t=1;

    cin>>t;

    while(t--)

    {

        solve();

    }

}



Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>



using namespace std;



void solve()

{

    int n;

    cin>>n;

    deque<char> dq;

    char c;

    for(int i=1;i<=n;i++)

    {

        cin>>c;

        dq.push_back(c);

    }

    while(!dq.empty() && dq.front()=='s')

    {

        dq.pop_front();

    }

    while(!dq.empty() && dq.back()=='p')

    {

        dq.pop_back();

    }

    int np=0,ns=0;

    for(auto c:dq)

    {

        if(c=='p')

        {

            np++;

        }

        else if(c=='s')

        {

            ns++;

        }

    }

    if(np==0 || ns==0)

    {

        cout<<"YES"<<endl;

    }

    else

    {

        cout<<"NO"<<endl;

    }

}



int main()

{

    int t=1;

    cin>>t;

    while(t--)

    {

        solve();

    }

}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define int long long
#define ll long long
#define mod 1000000007

vector<int> f(int n) {
    vector<int> v(61, 0);
    for (int i = 60; i >= 0; --i) {
        v[i] = (n & 1);
        n >>= 1;
    }
    return v;
}

signed main(){
    fast_io;
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<set<int>> adj(n+1);
        vector<int> count(n+1,0);
        for(int i=0;i<n-1;i++){
            int u,v;
            cin>>u>>v;
            adj[u].insert(v);
            adj[v].insert(u);
            count[u]++;
            count[v]++;
        }
        map<int,set<int>> mp;
        set<int> sety;
        for(int i=1;i<=n;i++){
            mp[count[i]].insert(i);
            sety.insert(count[i]);
        }
        if(n==2){
            cout<<0<<endl;
        }
        else{
        int count1=mp[*sety.rbegin()].size();
        //cout<<count1<<endl;
        if(count1==1 && sety.size()>1){
            int flag=0;
            int ans=*sety.rbegin();
            //cout<<ans<<endl;
            auto it2=sety.rbegin();
            ++it2;
            int val=*it2;
            ans+=val;
            //cout<<ans<<endl;
            int maxval=*mp[*sety.rbegin()].begin();
            //cout<<maxval<<endl;
            for(auto it:mp[val]){
                if(!adj[maxval].count(it)){
                    flag=1;
                    break;
                }
            }
            if(!flag){
                ans-=2;
            }
            else{
                ans--;
            }
            cout<<ans<<endl;
        }
        else{ 
            int ans=((*sety.rbegin())*2)-1;
            cout<<ans<<endl;
        }
        }
    }   
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define MAX 0x3f3f3f3f
#define endl "\n"
using namespace std;
using ll = long long;

void solve(){
	ll l,r;
	cin>>l>>r;
	ll a=0;
	ll b=0;
	ll c=0;
	for(ll i=30;i>=0;i--){
		ll d=(1ll<<i);
		if((d&r)>0&&(d&l)==0){
			a+=d;
			b+=d-1;
			c+=d-2;
			break;
		}
		if((d&r)==(d&l)){
			a+=(d&r);
			b+=(d&l);
			c+=(d&l);
		}
	}
	cout<<a<<" "<<b<<" "<<c<<endl;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// solve();
	ll t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define MAX 0x3f3f3f3f
#define endl "\n"
using namespace std;
using ll = long long;

void solve(){
	ll l,r;
	cin>>l>>r;
	ll a=0;
	ll b=0;
	ll c=0;
	for(ll i=30;i>=0;i--){
		ll d=(1ll<<i);
		if((d&r)>0&&(d&l)==0){
			a+=d;
			b+=d-1;
			c+=d-2;
			break;
		}
		if((d&r)==(d&l)){
			a+=(d&r);
			b+=(d&l);
			c+=(d&l);
		}
	}
	if(c<l){
		c=a+1;
	}
	cout<<a<<" "<<b<<" "<<c<<endl;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// solve();
	ll t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define MAX 0x3f3f3f3f
#define endl "\n"
using namespace std;
using ll = long long;

void solve(){
	ll l,r;
	cin>>l>>r;
	ll a=0;
	ll b=0;
	ll c=r;
	for(ll i=30;i>=0;i--){
		ll d=(1ll<<i);
		if((d&r)>0&&(d&l)==0){
			a+=d;
			b+=d-1;
			break;
		}
		if((d&r)==(d&l)){
			a+=(d&r);
			b+=(d&l);
		}
	}
	cout<<a<<" "<<b<<" "<<c<<endl;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// solve();
	ll t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define MAX 0x3f3f3f3f
#define endl "\n"
using namespace std;
using ll = long long;

void solve(){
	ll l,r;
	cin>>l>>r;
	ll a=0;
	ll b=0;
	ll c=0;
	for(ll i=30;i>=0;i--){
		ll d=(1ll<<i);
		if((d&r)>0&&(d&l)==0){
			a+=d;
			b+=d-1;
			c+=d-2;
			break;
		}
		if((d&r)==(d&l)){
			a+=(d&r);
			b+=(d&l);
			c+=(d&l);
		}
	}
	cout<<a<<" "<<b<<" "<<c<<endl;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// solve();
	ll t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define MAX 0x3f3f3f3f
#define endl "\n"
using namespace std;
using ll = long long;

void solve(){
	ll l,r;
	cin>>l>>r;
	ll a=0;
	ll b=0;
	ll c=r;
	for(ll i=30;i>=0;i--){
		ll d=(1ll<<i);
		if((d&r)>0&&(d&l)==0){
			a+=d;
			b+=d-1;
			break;
		}
		if((d&r)==(d&l)){
			a+=(d&r);
			b+=(d&l);
		}
	}
	cout<<a<<" "<<b<<" "<<c<<endl;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// solve();
	ll t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Memory limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, k, n) for (long long i = k; i < n; ++i)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;

const int MOD = 1e9 + 7;

int helper(int ind, int i, int j, string &a, string &b, string &c, vector<vector<vector<int>>> &dp) {
    if (ind == c.length()) return 0; // If all characters of 'c' are processed
    if (dp[ind][i][j] != -1) return dp[ind][i][j]; // Memoization

    int from_a = INT_MAX, from_b = INT_MAX;

    // Option 1: Take from 'a' if possible
    if (i < a.length()) {
        if (c[ind] == a[i])
            from_a = helper(ind + 1, i + 1, j, a, b, c, dp);
        else
            from_a = 1 + helper(ind + 1, i + 1, j, a, b, c, dp);
    }

    // Option 2: Take from 'b' if possible
    if (j < b.length()) {
        if (c[ind] == b[j])
            from_b = helper(ind + 1, i, j + 1, a, b, c, dp);
        else
            from_b = 1 + helper(ind + 1, i, j + 1, a, b, c, dp);
    }

    return dp[ind][i][j] = min(from_a, from_b); // Take the minimum of both options
}

void solve() {
    string a, b, c;
    cin >> a >> b >> c;
    int n = c.length();
    vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(a.length() + 1, vector<int>(b.length() + 1, -1)));

    int ans = helper(0, 0, 0, a, b, c, dp);
    cout << ans << endl;
}

int main() {
    IOS;
    ll t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

void solve(){
    int n;
    cin>>n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin>>v[i];
    }
    
    // ll cnt=0;
    vector<pair<int,int>> ans;
    for (int i = 1; i <= n; i++)
    {
        // bool flag=true;
        for (int j = 0; j < n; j++)
        {
            if(v[j]==i){
                // flag=false;
                break;
            }
            if(v[j]>i){
                ans.push_back({v[j],i});
            }
            else if(v[j]<i){
                ans.push_back({v[j],i});
                ans.push_back({i,v[j]});
            }
        }
        
    }

    cout<<ans.size()<<endl;
    for (int i = 0; i < ans.size(); i++)
    {
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}

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

Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

void solve(){
    int n;
    cin>>n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin>>v[i];
    }
    
    // ll cnt=0;
    vector<pair<int,int>> ans;
    for (int i = 1; i <= n; i++)
    {
        // bool flag=true;
        for (int j = 0; j < n; j++)
        {
            if(v[j]==i){
                // flag=false;
                break;
            }
            if(v[j]>i){
                ans.push_back({v[j],i});
            }
            else if(v[j]<i){
                ans.push_back({i,v[j]});
                ans.push_back({v[j],i});
            }
        }
        
    }

    cout<<ans.size()<<endl;
    for (int i = 0; i < ans.size(); i++)
    {
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}

int main(){
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

void solve(){
    int n;
    cin>>n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin>>v[i];
    }
    
    // ll cnt=0;
    vector<pair<int,int>> ans;
    for (int i = 1; i <= n; i++)
    {
        // bool flag=true;
        for (int j = 0; j < n; j++)
        {
            if(v[j]==i){
                // flag=false;
                break;
            }
            if(v[j]>i){
                ans.push_back({v[j],i});
            }
            else if(v[j]<i){
                ans.push_back({v[j],i});
                ans.push_back({i,v[j]});
            }
        }
        
    }

    cout<<ans.size()<<endl;
    for (int i = 0; i < ans.size(); i++)
    {
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}

int main(){
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

void solve(){
    int n;
    cin>>n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin>>v[i];
    }
    
    // ll cnt=0;
    vector<pair<int,int>> ans;
    for (int i = 1; i <= n; i++)
    {
        // bool flag=true;
        for (int j = 0; j < n; j++)
        {
            if(v[j]==i){
                // flag=false;
                break;
            }
            if(v[j]>i){
                ans.push_back({v[j],i});
            }
            else if(v[j]<i){
                ans.push_back({i,v[j]});
                ans.push_back({v[j],i});
            }
        }
        
    }

    cout<<ans.size()<<endl;
    for (int i = 0; i < ans.size(); i++)
    {
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}

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

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

void solve(){
    int n;
    cin>>n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin>>v[i];
    }
    
    // ll cnt=0;
    vector<pair<int,int>> ans;

    set<int> s;
    for (int i = 0; i < n; i++)
    {
        for (int j = v[i]+1; j <= n; j++)
        {
            if(s.find(j)!=s.end()) continue;
            ans.push_back({j,v[i]});
        }
        for (int j = n; j >= 1; j--)
        {
            if(j==v[i]) continue;
            if(s.find(j)!=s.end()) continue;
            ans.push_back({v[i],j});
        }
        s.insert(v[i]);
    }
    

    cout<<ans.size()<<endl;
    for (int i = 0; i < ans.size(); i++)
    {
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}

int main(){
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 12):
#include <bits/stdc++.h>
using namespace std;
#define int long long

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        if(n == 1){
            cout << 0 << "\n";
            continue;
        }
        
        
        vector<vector<int>> adj(n+1);
        vector<int> degree(n+1, 0);vector<pair<int,int>>v1(n-1);
        for(int i = 0; i < n-1; i++){
            int u, v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
            degree[u]++;
            degree[v]++;
            v1[i].first=u,v1[i].second=v;
        }
        
        
        for (int i = 1; i <= n; i++){
            sort(adj[i].begin(), adj[i].end());
        }
        
        
        vector<pair<int,int>> vertices;
        vertices.reserve(n);
        for(int i = 1; i <= n; i++){
            vertices.push_back({degree[i], i});
        }
        sort(vertices.begin(), vertices.end(), [&](auto &a, auto &b){
            return a.first > b.first;
        });
        
        // We only need to check the top k candidates.
        int k = min(n, (int)200);
        int ans = 0;
        
        auto isAdjacent = [&](int u, int v) -> bool {
           
            return binary_search(adj[u].begin(), adj[u].end(), v);
        };
        
       
        for (int i = 0; i < k; i++){
            for (int j = i + 1; j < k; j++){
                int u = vertices[i].second;
                int v = vertices[j].second;
                if (!isAdjacent(u, v)){
                    ans = max(ans, vertices[i].first + vertices[j].first);
                    
                    break;
                }
            }
        }
        int maxi=0;
        for(int  i=0;i<n-1;i++) maxi=max(maxi,degree[v1[i].first]+degree[v1[i].second]-1);
        cout << max(maxi-1,ans-1) << "\n";
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 7):
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pi pair<int,int>
#define int long long int
#define nl cout<<endl;
#define PB push_back
#define MP make_pair
#define f(a,b) for(int i = a; i < b; i++)
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
    int t=1;
    cin>>t;
    while(t--){
        string s;
        cin >> s;

        int n = s.length();

        int val1, val2, maxi, ind;
        f(0,n-1){
            if(s[i] < '8'){
                val1 = s[i] - '0';
                maxi = val1;
                ind = i;
                for(int j = i + 1; j <= min(i+8,n-1); j++){
                    val2 = s[j] - '0';
                    val2 -= (j - i);
                    if(val2 > maxi){
                        maxi = val2;
                        ind = j;
                    }
                    if(maxi == 9 - (j - i)) break;
                }
                char c = maxi + '0';
                s = s.substr(0,i) + c + s.substr(i,ind-i) + s.substr(ind+1);
            }
        }
        cout << s;
        nl
    }	
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pi pair<int,int>
#define int long long int
#define nl cout<<endl;
#define PB push_back
#define MP make_pair
#define f(a,b) for(int i = a; i < b; i++)
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
    int t=1;
    cin>>t;
    while(t--){
        string s;
        cin >> s;

        int n = s.length();

        int val1, val2, maxi, ind;
        f(0,n-1){
            if(s[i] < '8'){
                val1 = s[i] - '0';
                maxi = val1;
                ind = i;
                for(int j = i + 1; j <= min(i+8,n-1); j++){
                    val2 = s[j] - '0';
                    val2 -= (j - i);
                    if(val2 > maxi){
                        maxi = val2;
                        ind = j;
                    }
                    if(maxi == 9 - (j - i)) break;
                }
                char c = maxi + '0';
                // s = s.substr(0,i) + c + s.substr(i,ind-i) + s.substr(ind+1);
                while(ind > i){
                    s[ind] = s[ind-1];
                    ind--;
                }
                s[ind] = c;
            }
        }
        cout << s;
        nl
    }	
    return 0;
}