//     AUTHOR :-   Sagnik Mitra
//     Jalpaiguri Govt. Engg College
#include <bits/stdc++.h>
using namespace std;
//templates//
#define ll                   long long int
#define f(i,n)               for(i=0;i<n;i++)
#define w(t)                 int t; cin>>t; while(t--)
#define mod                  1000000007
#define out(p)               cout<<p<<"\n"
#define pb                   push_back
#define eb                   emplace_back
#define vl                   vector<ll>
#define uml                  unordered_map<ll,ll>
#define ml                   map<ll,ll>
#define ql                   queue<ll>
#define F                    first
#define S                    second
#define mem(a,n)             memset(a,n,sizeof(a))
void stugs(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
}
struct node{
	int data;
	struct node* next;
};
int main(){
    
    stugs();
    ll i=0,in=1;
    ll vis[500005]={0};
    set<pair<ll,ll>> s;
    w(t){
        ll a;
        cin>>a;
        if(a==1){
            ll b;
            cin>>b;i++;
            s.insert({-b,i});
        }
        else if(a==2){
            while(vis[in]==1){
                in++;
            }
            cout<<in<<" ";
            vis[in]=1;
        }
        else{
            // for(auto it:s){
            //     if(vis[it.S]==0){
            //         cout<<it.S<<" ";
            //         vis[it.S]=1;break;
            //     }
            //     else{
            //         s.erase(it);
            //     }
            // }
            auto it=s.begin();
                //cout<<(*it).F<<" "<<(*it).S<<"\n";
 
                while(vis[(*it).S]){
                    s.erase(it);
                    it=s.begin();
                }
                vis[(*it).S]=1;
                cout<<(*it).S<<" ";
        }
    }
	return 0;
}