#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
using namespace std;
const int sz = 5e5  + 5;
const ll mod =  1e9 + 7;
const ll inf = 1e9;
const double eps = 1e-8;
bool is_vowel(char a){ return (a=='A' || a=='E' || a=='O' || a=='I' || a=='U');}
//int dx[] = {2,-2,2,-2,1,1,-1,-1}, dy[] = {1,1,-1,-1,2,-2,2,-2}; // knight moves
//int dx[] = {0,0,1,1,1,-1,-1,-1}, dy[] = {-1,1,-1,0,1,-1,0,1}; //neighbours
int vis[sz] {0};
void test() {
    multiset<pair<int,int> > ms;
    vector<int> v,ans;
    v.pb(0);
    int q,p = 1,no = 1, customer_no = 1;cin>>q;
    while(q--)
    {
        int t;scanf("%d", &t);
        if(t==1)
        {
            int m;scanf("%d", &m);
            ms.insert({m,no++});
            v.pb(m);
        }
        else if(t==2)
        {
            for(; p < no;p++)
            {
                if(vis[p])
                    continue;
                break;
            }
            ms.erase({v[p], p});
            ans.pb(p++);
        }
        else
        {
            auto it = ms.end();
            it--;
            pair<int,int> temp = *it;
            it = ms.lower_bound({temp.first, 0});
            auto res = *it;
            ans.pb(res.second);
            vis[res.second] = 1;
            ms.erase(it);
        }
    }
    for(int i = 0;i < ans.size();i++)
        cout<<ans[i]<<' ';
}
int main(){
    int cases = 1;
//    cin>>cases;
    while(cases--)
        test();
}