#include<bits/stdc++.h>
using namespace std;
typedef struct LNode{
int data;
struct LNode * next;
}LNode;
LNode *phead=NULL;
void insert(int x,int y){
if(phead==NULL) return;
LNode *p=phead;
while(p!=NULL&&p->data!=x){
p=p->next;
}
LNode *pTemp=new LNode();
pTemp->next=p->next;
pTemp->data=y;
p->next=pTemp;
}
void detele(int x){
if(phead==NULL) return;
LNode *p=phead;
while(p!=NULL&&p->data!=x){
p=p->next;
}
if(p==NULL||p->next==NULL) return;
LNode *q=p->next;
p->next=q->next;
delete q;
return;
}
void search(int x){
if(phead==NULL) return;
LNode *p=phead;
while(p!=NULL&&p->data!=x){
p=p->next;
}
if(p->next==NULL) cout << 0 << endl;
else cout << p->next->data << endl;
}
void printList() {
LNode* current = phead;
while (current!= NULL) {
printf("%d ", current->data);
current = current->next;
}
printf("\n");
}
int main(){
int k;
cin >> k;
phead = new LNode();
phead->data = 1;
phead->next = NULL;
while(k--){
int opt;
cin >> opt;
if(opt==1){
int x,y;
cin >> x >> y;
insert(x,y);
}else if(opt==2){
int x;
cin >> x;
search(x);
}else{
int x;
cin >> x;
detele(x);
}
}
return 0;
}