#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ini(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define int int64_t
#define inf LLONG_MAX

void solve()
{
    deque<int> mono;
    priority_queue< pair<int,int> ,vector<pair<int,int>>,greater<pair<int,int>>> poly;
    map<int,bool> status;

    int n,tot=1;
    cin>>n;

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

        if(type == 1)
        {
            int m;
            cin>>m;

            poly.push({-m,tot});
            mono.push_back(tot);
            tot++;
            status[tot]=false;
        }
        else if(type == 2)
        {
            while(mono.size())
            {
                int curr = mono.front();
                mono.pop_front();

                if(status[curr])
                    continue;

                cout<<curr<<' ';
                status[curr] = true;
                break;
            }
        }
        else if(type == 3)
        {
            while(poly.size())
            {
                auto curr = poly.top();
                poly.pop();

                if(status[curr.second])
                    continue;

                cout<<curr.second<<' ';
                status[curr.second] = true;
                break;
            }
        }
    }
    
}


signed main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    // int tt;    cin>>tt;    while(tt--)
        solve();
     
    cerr<<" Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s \n";
        
        
return 0;
}