#include<bits/stdc++.h>
using namespace std;
typedef struct LNode{
int data;
struct LNode * next;
}LNode;
LNode *phead=NULL;
LNode* zw(int x,LNode *p){
LNode *t=phead;
while(t!=NULL&&t->data!=x){
t=t->next;
}
return t;
}
void insert(int x,int y){
if(phead==NULL) return;
LNode *p=zw(x,phead);
LNode *pTemp=(LNode *)malloc(sizeof(LNode));
pTemp->next=p->next;
pTemp->data=y;
p->next=pTemp;
}
void detele(int x){
if(phead==NULL) return;
LNode *p=zw(x,phead);
if(p==NULL||p->next==NULL) return;
LNode *q=p->next;
p->next=q->next;
free(q);
return;
}
void search(int x){
if(phead==NULL) return;
LNode *p=zw(x,phead);
if(p->next==NULL) cout << 0 << endl;
else cout << p->next->data << endl;
}
int main(){
int k;
cin >> k;
phead = (LNode*)malloc(sizeof(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;
}