//you can do anything  //  be strong :| 
#include <bits/stdc++.h> 
#define ll long long
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pk push_back
#define ff first
#define ss second 		
using namespace std;
const ll maxn = 1e5+5 ;

void solve()
{	
	int n  ,m ,r ,count=1;
	scanf("%d" ,&n);
	priority_queue<pair<ll ,ll> , vector<pair<ll ,ll>>, greater<pair<ll ,ll>>  > PQ;
	queue<pair<ll ,ll>>Q;
	vector<ll>ans ,vis;
	
	while(n--)
	{
		scanf("%d" ,&m);
		if(m==1)
		{
			scanf("%d" ,&r);
			PQ.push({-r ,count});
			Q.push({-r ,count});
			count++ ;
			vis.pk(0);
		}
		else if(m==2)
		{
			pair<ll ,ll>cur ;
			
			do
			{
				cur = Q.front();
				Q.pop();
			}while(vis[cur.ss-1]);
			
			ans.pk(cur.ss);
			vis[cur.ss-1]=1;
		}
		else 
		{
					pair<ll ,ll>cur ;
			
			do
			{
				cur = PQ.top();
				PQ.pop();
			//	cout<<" cur.ss-1 = "<<cur.ss-1<<" cur.ff = "<<cur.ff<<"\n";
			}while(vis[cur.ss-1]);
			
			ans.pk(cur.ss);
			vis[cur.ss-1]=1;
		}
	}
	
	for(auto i : ans) cout<<i<<" ";
	
}

int main()
{

	ll t=1; 
	//scanf("%lld" ,&t);
	while(t--) solve();
}


