#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
    ll t, id = 0;
    set< pair<ll, ll> > poli, mono;
    cin >> t;
    while(t--){
        ll q;
        cin >> q;
        if(q == 1){
            id++;
            ll x;
            cin >> x;
            mono.insert({id, -x});
            poli.insert({-x, id});
        }
        else if(q == 2){
            auto pr = *mono.begin();
            cout << pr.first << " ";
            mono.erase(pr);
            swap(pr.first, pr.second);
            poli.erase(pr);
        }
        else{
            auto pr = *poli.begin();
            cout << pr.second << " ";
            poli.erase(pr);
            swap(pr.first, pr.second);
            mono.erase(pr);
        }
    }



    return 0;
}
