//Linkwish's code
#include<bits/stdc++.h>
#define endl '\n'
#define si inline
#define fi first
#define se second
using namespace std;
typedef long long ll;typedef __int128 li;typedef long double ld;
typedef pair<int,int> pii;typedef pair<ll,ll> pll;
typedef const int ci;typedef const ll cl;ci iinf=INT_MAX;cl linf=LLONG_MAX;
template<typename T>si bool gmax(T &x,const T y){if(x<y)return x=y,1;return 0;}
template<typename T>si bool gmin(T &x,const T y){if(y<x)return x=y,1;return 0;}
namespace LinkWish{
ci N=500005,lim=1e9;
vector<pii> p[N];
int n;
struct Hoshino{
int ls,rs,tag,emp;
}t[N*30];
int rt,cnt;
si int np(int len){
cnt++,t[cnt].emp=len;
t[cnt].ls=t[cnt].rs=0,t[cnt].tag=-1;
return cnt;
}
si void push_up(int x){t[x].emp=t[t[x].ls].emp+t[t[x].rs].emp;}
si void update(int x,int col){
p[col].emplace_back(x,t[x].emp);
t[x].emp=0,t[x].tag=col;
}
si void push_down(int x){
if(~t[x].tag){
if(t[t[x].ls].emp!=0)update(t[x].ls,t[x].tag);
if(t[t[x].rs].emp!=0)update(t[x].rs,t[x].tag);
t[x].tag=-1;
}
}
void modify(int &x,int l,int r,int c,int &k){
if(t[x].emp==0)return ;
if(k>=t[x].emp)return k-=t[x].emp,update(x,c),void();
p[c].emplace_back(x,0);
int mid=(l+r)>>1;
if(t[x].ls==0)t[x].ls=np(mid-l+1);
if(t[x].rs==0)t[x].rs=np(r-mid);
push_down(x);
modify(t[x].ls,l,mid,c,k);
if(k>0)modify(t[x].rs,mid+1,r,c,k);
push_up(x);
}
int ask(int x,int l,int r,int goal){
if(l==r)return t[x].tag;
int mid=(l+r)>>1;
if(t[x].ls==0||t[x].rs==0)return t[x].tag;
push_down(x);
if(goal<=mid)return ask(t[x].ls,l,mid,goal);
return ask(t[x].rs,mid+1,r,goal);
}
int tot;
si void ins(int k){
tot++;
modify(rt,1,lim,tot,k);
}
int ct;
si void era(int id){
vector<int> tmp;
for(pii i:p[id]){
int x=i.fi,v=i.se;
if(t[x].tag==id)t[x].emp=v,t[x].tag=-1;
else push_down(x),tmp.push_back(x);
}
for(auto it=tmp.rbegin();it!=tmp.rend();it++)push_up(*it);
p[id].clear(),p[id].shrink_to_fit();
}
si void solve(){
cin>>n;
rt=np(lim);
while(n--){
int op,x;cin>>op>>x;
if(op==1)ins(x);
else if(op==2)era(x);
else{
int res=ask(rt,1,lim,x);
if(res==-1)cout<<"0\n";
else cout<<res<<endl;
}
}
}
void mian(){
solve();
}
}
signed main(){
#ifndef ONLINE_JUDGE
assert(freopen("in.in","r",stdin));
assert(freopen("out.out","w",stdout));
#endif
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
LinkWish::mian();
return 0;
}