//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")

/*
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠋⠀⠀⠀⡧⠚⠉⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡼
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⣰⠀⠀⠐⠀⣸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠁
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡷⠤⠤⢬⡀⠀⢀⣴⡷⠗⠚⣷⡤⠛⠉⠙⠮⡙⡄⠀⣸
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⠤⠔⠒⣒⡏⢀⣀⣀⡀⣿⠉⢅⠀⠐⠉⢠⢓⢤⡀⠀⠀⠀⠈⠂⠀⣿
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡤⠚⠁⠀⢀⣀⣐⣀⠀⠳⡇⠀⠀⠀⠀⠀⠀⢣⠀⡤⠧⢄⡀⠙⡓⢤⠀⠀⠀⠀⣿⢄⠀⠀⢠
⠀⣀⣀⣀⣀⣀⣀⣤⣀⠀⢀⠚⠚⠀⠦⡀⠠⣉⠉⠓⠀⠀⠀⠽⣄⠀⠀⠀⠀⠀⠀⡁⠀⠀⠀⠀⠀⠉⠙⣍⠙⠚⠉⢿⠉⢾
⠀⠈⢦⠠⠖⠂⠀⠀⠀⡳⠉⠁⠀⠀⠀⠀⢢⠀⠓⡀⠀⠀⠀⠀⠀⠑⠦⣒⣀⣀⣴⠜⠙⡛⠲⣀⣀⠀⠀⠁⡙⣄⡀⠘⡀
⠀⠀⠀⠙⢤⡀⠀⠀⣴⠀⠀⡇⠀⠀⠀⠀⠀⠹⡀⠀⢄⠀⠀⢀⠦⢠⠀⠀⠈⣄⠿⡇⢀⢹⠀⠀⠙⣄⣄⣀⠀⠢⠂⠉⢷
⠀⠲⣒⠒⡋⠄⡄⢠⠃⠀⠀⣇⠀⠀⠀⠀⠃⠀⠹⠳⡀⢦⡀⠀⠀⠀⠳⠀⠀⢎⣆⡇⠘⣸⡇⠀⠀⠀⠙⣀⢷⠀⠀⡄⠀⢧
⢤⠀⠀⠓⢤⣤⠤⣼⠀⠀⠀⠸⠀⠀⣄⠀⠀⠀⡀⢳⡉⠙⣞⣀⣄⠀⠀⠻⠀⢇⢘⡮⢢⣦⣧⠀⠀⠀⠀⠈⣯⠹⢦⣧⠀⠀⠳
⠀⣷⠀⠾⡵⣉⠀⣏⠀⠀⠀⠀⠹⠀⠈⠳⠀⠀⠈⣄⡖⠀⠀⣡⣶⢍⣟⠾⢳⢸⠀⠙⠀⡿⣷⣀⣀⣀⠀⡀⢸⠀⠀⠀⠀⠀⠀⠙
⠀⣿⠀⢸⠋⢸⠀⣿⠆⡀⢠⠀⠀⠘⣄⡀⠰⡀⠀⠈⡾⢫⣟⠖⣤⣸⡰⣧⠀⢿⣤⠀⠹⣷⢾⡉⢦⡀
⠀⠘⡦⠏⠀⢸⠀⢿⣦⠈⠀⠀⠀⡠⣅⠳⡀⠻⠆⠀⢹⠀⠈⠀⠈⠻⠿⠁⠀⠈⠀⡂⣇⢿⢦⠀⠦⡀⠀⠛⡭⠀⠀⠀⠀⠀⠀⣠
⠒⣡⢿⠀⠀⠀⡀⠸⡿⡰⠀⠀⡄⠀⢿⠀⠀⣒⣦⣃⠁⠀⠀⠀⠀⠀⠀⠈⠀⠀⠀⡟⢹⣆⣯⢿⡢⡀⡉⠉⠀⠀⠀⠀⠀⠀⠀⠙
⠒⠉⠉⣯⠉⠙⢳⢤⡿⠘⡀⢷⠀⠀⣾⠀⣷⢧⠤⢼⠦⢀⠀⠀⠀⠀⠀⠀⠀⠀⢀⢿⠀⣏⢦⠳⢤⣀
⠀⠀⠀⢹⡄⠀⠀⡄⣿⡷⡀⠂⡽⣠⠛⣍⢦⣀⠈⠙⠁⠀⠀⠀⠀⠀⠔⠀⠀⢠⠋⠀⢧⠘⣶⠈⠙⠯⠀⣀⠤⠒⠒⢄
⠀⠀⠀⠀⣿⠀⠀⢻⠃⠀⠈⠀⠉⣄⠙⠋⠃⢻⡟⢮⠀⠀⠀⠀⠀⠀⠀⠀⡴⣁⠖⣩⢞⢦⣝⣟⠛⣉⠝⠊⢉⡀⠀⠀⠈⢄
⠀⠀⠀⠀⠘⣇⠴⢹⢄⠀⠀⠈⠀⠸⡓⠛⢶⡀⣇⠱⡈⠓⡲⡒⠺⡉⠁⠠⣫⢶⣁⠞⠉⠁⣀⣠⣾⠤⡀⠀⣿⢳⣀⡖⠙⢦⢻
⠀⠀⠀⢀⠖⢻⣄⣀⣿⣄⠀⠀⠹⢤⣘⢦⠀⣰⣽⠀⣽⠹⡇⠙⣄⠸⣦⣾⣒⠯⠒⠚⠛⣽⠋⠉⠢⠀⠈⠀⠀⠉⠷⡛⡁⡦⠒⢧
⠀⢀⠞⠀⠀⡟⡴⣚⠿⠑⠗⠄⣀⡇⠀⠀⠀⠳⡇⠀⠿⣀⠷⠒⠉⠀⠈⠙⡄⠀⠀⠀⢠⠷⡀⠀⠀⠀⣰⣄⡄⠀⠀⠙⣦⣾
⡴⠁⠀⠀⠀⡿⣠⢁⠞⣹⠀⠀⣀⡀⠀⠀⠀⠀⠀⠀⠀⣾⠀⠀⠀⠀⠀⠀⠀⠳⣀⠀⠀⠀⠀⠈⠙⢿⢝⣯⣍⠒⠐⡛⢓⢤⣯⡆
⠀⠀⠀⠀⠀⠻⡄⠈⠀⡷⠋⠀⠀⠈⠁⡇⠀⠀⠀⠀⠀⡿⠀⠀⠀⠀⠀⠀⣠⢋⠯⢯⠀⠀⡤⢻⠈⡄⠳⠀⣷⡀⠀⡴⡵⣕⣿⡣
⠀⠀⠀⠀⠀⠀⠀⠲⡞⠳⣄⠀⠀⠀⢠⡇⠀⠀⠀⠰⡾⠉⠞⠀⢳⠶⣤⢰⢠⡁⢦⠑⡷⣿⡴⡟⠀⢃⠀⣳⢳⢎⣤⡯⠋⠓⣿⡝
⠀⠀⠀⠀⠀⣠⠚⠉⠳⡀⠈⣷⣄⠀⠈⣻⡀⠀⠀⠀⡏⡅⠀⣤⠉⠑⣬⣿⡟⡈⠀⢹⠭⠥⣿⠥⣽⡭⢓⣉⠧⠳⣿⣿⣟⠲⢤⣷
*/

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

/* abbr */
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define srt(x) sort(all(x))
#define uni(x) sort(all(x)), x.erase(unique(all(x)), x.end())
#define msv(x, v) memset(x, v, sizeof(x))
#define ms(x) memset(x, 0, sizeof(x))
#define mc(x, y) memcpy(x, y, sizeof(y))

/* typedef for long long */

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

/* typedef for other */

typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

/* typedef for point */

//typedef pii point;
//#define x first
//#define y second

/* typedef for vector */

typedef vector<int> vi;
typedef vector<ll> vl;

/* constant number */

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos((long double) - 1.0);
const double EPS = 1e-10;
const int MOD = 1073741824;

template <typename T>
void cmin(T &x, T y) {
    if(y < x)
        x = y;
}

template <typename T>
void cmax(T &x, T y) {
    if(y > x)
        x = y;
}

#define dbg(x) cerr << #x " = " << (x) << endl

ll qpow(ll x, ll n, ll mod = MOD) {
    if(n < 0)
        return 0;
    ll res = 1;
    while(n) {
        if(n & 1)
            res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

ll sq(ll x) {
    return x * x;
}

double sq(double x) {
    return x * x;
}

bool vis[500005];
queue<pii>Q;
priority_queue<pii>PQ;

namespace Solver {

    void InitOnce() {
#ifdef LOCAL
        freopen("A.txt", "r", stdin);
#endif // LOCAL
        int t;
        //scanf("%d", &t);
    }

    int q;

    void Read() {
        int res = scanf("%d", &q);
        if(res == -1)
            exit(0);
    }

    vector<int>ans;

    void Solve() {
        while(!Q.empty())
            Q.pop();
        while(!PQ.empty())
            PQ.pop();
        for(int i = 1; i <= q; ++i)
            vis[i] = 0;
        ans.clear();
        int id = 0;
        while(q--) {
            int t;
            scanf("%d", &t);
            if(t == 1) {
                int x;
                scanf("%d", &x);
                ++id;
                Q.push({x, -id});
                PQ.push({x, -id});
            } else if(t == 2) {
                while(1) {
                    int u = -Q.front().second;
                    Q.pop();
                    if(vis[u])
                        continue;
                    vis[u] = 1;
                    ans.push_back(u);
                    break;
                }
            } else {
                while(1) {
                    int u = -PQ.top().second;
                    PQ.pop();
                    if(vis[u])
                        continue;
                    vis[u] = 1;
                    ans.push_back(u);
                    break;
                }
            }
        }
        for(auto i : ans)
            cout << i << " ";
        cout << endl;
    }
}

int main() {
    Solver::InitOnce();
    while(true) {
        Solver::Read();
        Solver::Solve();
    }
    return 0;
}
