 #include <bits/stdc++.h>
const long long  mod=1e9+7;
const int inf=2e9;
typedef long long ll;
typedef unsigned long long ull;
const ll linf=1e18;
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define lson p<<1
#define rson p<<1|1
using namespace std;
const int maxn=1e6+15;



set<pii>s2,s3;
int cost[maxn];
int num;
int main()
{
    int q;
    scanf("%d",&q);
    int sum=0;
    while(q--){
        int op;
        scanf("%d",&op);
        if(op==1){
            scanf("%d",&cost[++num]);
            s2.insert(pii(num,num));
            s3.insert(pii(-cost[num],num));
        }
        else if(op==2){
            if(sum++) printf(" ");
            auto x=s2.begin();
            auto p=s3.lower_bound(pii(-cost[(*x).fi],(*x).fi));
            s3.erase(p);
            printf("%d",(*x).fi);
            s2.erase(x);
        }
        else{
            if(sum++) printf(" ");
            auto x=s3.begin();
            auto p=s2.lower_bound(pii((*x).se,(*x).se));
            s2.erase(p);
            printf("%d",(*x).se);
            s3.erase(x);
        }
    }
    printf("\n");
    return 0;
}

