#include<iostream>
#include<algorithm>
#include<set>
#include<utility>
using namespace std;
int main()
{
 /// freopen("input.txt","r",stdin);
  ///freopen("output.txt","w",stdout);
  long long q,i=1,w;
  cin>>q;
  set<pair<long long,long long>>M,P;
  for(w=1;w<=q;w++)
  {
    int m;
    cin>>m;
    if(m==1)
    {
      long long a;
      cin>>a;
      M.insert({i,-a});
      P.insert({-a,i});
      i++;
    }
    else if(m==2)
    {
      auto it=*M.begin();
      cout<<it.first<<" ";
      M.erase(it);
      swap(it.first,it.second);
      P.erase(it);
    }
    else
    {
      auto it=*P.begin();
      cout<<it.second<<" ";
      P.erase(it);
      swap(it.first,it.second);
      M.erase(it);
    }
    
  }
  cout<<endl;
  return 0;

}