#include<bits/stdc++.h>
using namespace std;
struct node{
int num;
node *next;
};
node *p,*h,*r;
int q,way,x,y;
void go_into(node *p,node *h,int x,int y);
void get(node *p,node *h,int x);
void del(node *p,node *h,int x);
int main(){
h=new node;
h->num=1;
r=h;
cin>>q;
for(int i=1;i<=q;i++){
cin>>way;
if(way==1){
cin>>x>>y;
go_into(p,h,x,y);
}else if(way==2){
cin>>x;
get(p,h,x);
}else{
cin>>x;
del(p,h,x);
}
}
return 0;
}
void go_into(node *p,node *h,int x,int y){
node *s;
s=new node;
p=h;
while(p->num!=x){
p=p->next;
}
s->next=p->next;
s->num=y;
p->next=s;
}
void get(node *p,node *h,int x){
p=h;
while(p->num!=x){
p=p->next;
}
cout<<p->next->num<<endl;
}
void del(node *p,node *h,int x){
node *s;
s=new node;
p=h;
while(p->num!=x){
p=p->next;
}
s=p->next->next;
p->next=s;
}