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

struct Node3{
    int idx, mon;
    Node3(){}
    Node3(int _idx, int _m): idx(_idx), mon(_m){}
    bool operator<(const Node3& a)const{
        if (mon == a.mon) return idx > a.idx;
        return mon < a.mon;
    }
};
priority_queue<int, vector<int>, greater<int> > q2;
priority_queue<Node3> q3;
bool vis[500050];
int id, ans[500050], cnt;

int main(){
    int q; scanf("%d", &q);
    for (int i = 1; i <= q; i++){
        int x; scanf("%d", &x);
        if (x == 1){
            int m; scanf("%d", &m);
            ++id;
            q2.push(id);
            q3.push(Node3(id, m));
        }else if (x == 2){
            while (vis[q2.top()]) q2.pop();
            ans[++cnt] = q2.top();
            vis[q2.top()] = true;
            q2.pop();
        }else{
            while (vis[q3.top().idx]) q3.pop();
            ans[++cnt] = q3.top().idx;
            vis[q3.top().idx] = true;
            q3.pop();
        }
    }
    for (int i = 1; i <= cnt; i++) printf("%d%c", ans[i], " \n"[i==cnt]);
    return 0;
}
