#include<bits/stdc++.h>
using namespace std;
struct ListNode{
int val;
ListNode* next;
};
ListNode* addNode(ListNode* L,int v,int num){
ListNode* dummyHead = new ListNode;
dummyHead->val=0;
dummyHead->next=L;
ListNode* cur = dummyHead;
while(cur!=NULL){
if(cur->val==v){
ListNode* node =new ListNode;
node->val=num;
node->next=cur->next;
cur->next=node;
}
cur =cur ->next;
}
return dummyHead->next;
}
ListNode* deleteList(ListNode* L,int constant){
ListNode* dummyHead = new ListNode;
dummyHead->val=0;
dummyHead->next=L;
ListNode* cur =dummyHead;
while(cur->next!=NULL){
if(cur->next->val==constant){
ListNode* temp = cur->next;
cur->next=cur->next->next;
delete temp;
}
else{
cur = cur->next;
}
}
return dummyHead->next;
}
ListNode* askList(ListNode* L,int constant){
ListNode* cur = L;
while(cur!=NULL){
if(cur->val==constant){
if(cur->next->next==NULL){
cout<<"0"<<endl;
break;
}
else{
cout<<cur->next->val<<endl;
break;
}
}
else{
cur=cur->next;
}
}
}
void printList(ListNode *L){
ListNode* cur=L;
while(cur!=NULL){
cout<<cur->val<<" ";
cur=cur->next;
}
cout<<endl;
}
int n,m;
int main(){
cin>>n;
ListNode* L=new ListNode;
L->val=1;
L->next=NULL;
for(int i=1;i<=n;i++){
int aa;
cin>>aa;
if(aa==1){
int bb,cc;cin>>bb>>cc;
addNode(L,bb,cc);
}
if(aa==2){
int bb;cin>>bb;
askList(L,bb);
}
if(aa==3){
int bb;cin>>bb;
deleteList(L,bb);
}
}
return 0;
}